Class OnecJdbcConverter
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.core.env.EnvironmentCapable,org.springframework.data.jdbc.core.convert.JdbcConverter,org.springframework.data.relational.core.conversion.RelationalConverter
MappingJdbcConverter that fixes how framework enums map onto their database column type.
Spring Data JDBC resolves the column type of any enum property to String via
JdbcColumnTypes (which hard-maps Enum -> String) before consulting custom
conversions. The schema generator, however, emits a UUID column for @Enumeration
attributes (each enum value has a stable name-based UUID), and EnumUuidConverters registers
an Enum -> UUID writing converter. Because the converter's target (UUID) is never
asked for — the framework requests an Enum -> String conversion against the resolved column
type — the enum is bound as its name() string into a UUID column and the insert
fails at runtime (issue #26).
This subclass overrides getColumnType(RelationalPersistentProperty) so that any enum
for which a custom write target is registered (i.e. our framework enums, which convert to
UUID) reports that write target as its column type. With the column type now UUID,
the writing path converts the enum through EnumUuidConverters.EnumToUuid and binds a real
UUID. Enums without a custom write target keep Spring's default String behaviour.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.data.relational.core.conversion.MappingRelationalConverter
org.springframework.data.relational.core.conversion.MappingRelationalConverter.AggregatePathValueProvider, org.springframework.data.relational.core.conversion.MappingRelationalConverter.ConversionContext, org.springframework.data.relational.core.conversion.MappingRelationalConverter.DefaultConversionContext, org.springframework.data.relational.core.conversion.MappingRelationalConverter.DocumentValueProvider, org.springframework.data.relational.core.conversion.MappingRelationalConverter.ProjectingConversionContext, org.springframework.data.relational.core.conversion.MappingRelationalConverter.RelationalPropertyValueProvider -
Constructor Summary
ConstructorsConstructorDescriptionOnecJdbcConverter(org.springframework.data.relational.core.mapping.RelationalMappingContext context, org.springframework.data.jdbc.core.convert.RelationResolver relationResolver, org.springframework.data.convert.CustomConversions conversions, org.springframework.data.jdbc.core.convert.JdbcTypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionClass<?> getColumnType(org.springframework.data.relational.core.mapping.RelationalPersistentProperty property) Methods inherited from class org.springframework.data.jdbc.core.convert.MappingJdbcConverter
getTargetSqlType, newValueProvider, readAndResolve, readValue, writeJdbcValue, writeValueMethods inherited from class org.springframework.data.relational.core.conversion.MappingRelationalConverter
doReadProjection, getConversionContext, getEnvironment, getPotentiallyConvertedSimpleRead, getPropertyAccessor, introspectProjection, newProjectingConversionContext, project, read, read, readAggregate, readAggregate, readCollectionOrArray, readMap, setApplicationContextMethods inherited from class org.springframework.data.relational.core.conversion.AbstractRelationalConverter
getConversions, getConversionService, getEntityInstantiators, getMappingContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContextMethods inherited from interface org.springframework.data.jdbc.core.convert.JdbcConverter
getMappingContext, readAndResolve, readAndResolve, writeJdbcValueMethods inherited from interface org.springframework.data.relational.core.conversion.RelationalConverter
getConversionService, getEntityInstantiators, getPropertyAccessor, introspectProjection, project, read
-
Constructor Details
-
OnecJdbcConverter
public OnecJdbcConverter(org.springframework.data.relational.core.mapping.RelationalMappingContext context, org.springframework.data.jdbc.core.convert.RelationResolver relationResolver, org.springframework.data.convert.CustomConversions conversions, org.springframework.data.jdbc.core.convert.JdbcTypeFactory typeFactory)
-
-
Method Details
-
getColumnType
public Class<?> getColumnType(org.springframework.data.relational.core.mapping.RelationalPersistentProperty property) - Specified by:
getColumnTypein interfaceorg.springframework.data.jdbc.core.convert.JdbcConverter- Overrides:
getColumnTypein classorg.springframework.data.jdbc.core.convert.MappingJdbcConverter
-