Stefan Schilling (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOWIxMjRkNzU2...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-14042?atlOrigin=eyJpIjoiOWIxMj...
) HHH-14042 (
https://hibernate.atlassian.net/browse/HHH-14042?atlOrigin=eyJpIjoiOWIxMj...
) No Dialect mapping for JDBC type: AttributeConverter and OffsetDateTime (
https://hibernate.atlassian.net/browse/HHH-14042?atlOrigin=eyJpIjoiOWIxMj...
)
Issue Type: Bug Affects Versions: 5.3.12, 5.4.15 Assignee: Unassigned Components:
hibernate-core, hibernate-entitymanager Created: 26/May/2020 13:30 PM Environment:
SpringBoot 2.1.9 (tried with 2.3.0 as well)
Hibernate 5.3.12 (SpringBoot 2.3.0 brings 5.4.15)
H2 (1.4.199)
openjdk version "11" 2018-09-25 OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
Windows 10 Priority: Minor Reporter: Stefan Schilling (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Using Entity
@Entity
@Table(
name = "IMPORT_RECORD"
)
public class ImportRecordEntity implements Serializable {
private static final long serialVersionUID = 2483327758356663412L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID" )
private UUID id;
@Column(name = "IMPORT_TIME_UTC" , columnDefinition = "timestamp(9) WITH
TIME ZONE" )
private ImportTime importTime;
public UUID getId() {
return id;
}
public void setId( final UUID id) {
this.id = id;
}
public ImportTime getImportTime() {
return importTime;
}
public void setImportTime( final ImportTime importTime) {
this.importTime = importTime;
}
}
with ImportType
public final class ImportTime {
public static final ImportTime EMPTY = new ImportTime( null );
private final ZonedDateTime value;
private ImportTime( final ZonedDateTime pValue) {
value = pValue;
}
public ZonedDateTime getValue() {
return value;
}
public static ImportTime of( final ZonedDateTime pZonedDateTime) {
return ofNullable(pZonedDateTime).orElse(EMPTY);
}
}
and AttributeConverter<ImportTime, OffsetDateTime>
@Converter(autoApply = true )
public class ImportTimeAttributeConverter implements AttributeConverter<ImportTime,
OffsetDateTime> {
@Override
public OffsetDateTime convertToDatabaseColumn( final ImportTime pImportTime) {
return Optional.ofNullable(pImportTime)
.map(ImportTime::getValue)
.map(ZonedDateTime::toOffsetDateTime)
.orElse( null );
}
@Override
public ImportTime convertToEntityAttribute( final OffsetDateTime pImportTime) {
return Optional.ofNullable(pImportTime)
.map(OffsetDateTime::toZonedDateTime)
.map(ImportTime::of)
.orElse(ImportTime.EMPTY);
}
}
left me with the following Exception when trying to save the Entity to the DB
Hibernate: create table import_record (id varbinary not null , import_time_utc
timestamp(9) WITH TIME ZONE, primary key (id))
2020-05-26 21:49:18.842 INFO 9228 --- [ main]
o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation:
[org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-05-26 21:49:18.852 INFO 9228 --- [ main]
j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for
persistence unit ' default '
2020-05-26 21:49:20.040 INFO 9228 --- [ main]
c.e.e.p.p.r.ImportRecordRepositorySpec : Started ImportRecordRepositorySpec in 900.689
seconds (JVM running for 902.24)
2020-05-26 21:49:20.070 INFO 9228 --- [ main]
o.s.t.c.transaction.TransactionContext : Began transaction (1) for test context
[DefaultTestContext@457c9034 testClass = ImportRecordRepositorySpec, testInstance =
com.my.persistence.repository.ImportRecordRepositorySpec@3bde62ff, testMethod =
$spock_feature_0_0@ImportRecordRepositorySpec, testException = [ null ],
mergedContextConfiguration = [MergedContextConfiguration@345f69f3 testClass =
ImportRecordRepositorySpec, locations = '{}' , classes = '{ class
com.my.persistence.PersistenceConfiguration}' , contextInitializerClasses =
'[]' , activeProfiles = '{}' , propertySourceLocations = '{}' ,
propertySourceProperties =
'{org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper=
true }' , contextCustomizers =
set[org.spockframework.spring.mock.SpockContextCustomizer@0,
[ImportsContextCustomizer@50de186c key =
[org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,
org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,
org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,
org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration,
org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManagerAutoConfiguration]],
org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@3e2055d6,
org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@50f6ac94,
org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0,
org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@79defdc,
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@351584c0,
org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@f5a8e2f5,
org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@dc9876b,
org.springframework.boot.test.context.SpringBootTestArgs@1], contextLoader =
'org.springframework.boot.test.context.SpringBootContextLoader' , parent = [ null
]], attributes = map[[empty]]]; transaction manager
[org.springframework.orm.jpa.JpaTransactionManager@4e13af1b]; rollback [ true ]
Hibernate: insert into import_record (import_time_utc, id) values (?, ?)
2020-05-26 21:49:20.503 INFO 9228 --- [ main]
o.s.t.c.transaction.TransactionContext : Rolled back transaction for test:
[DefaultTestContext@457c9034 testClass = ImportRecordRepositorySpec, testInstance =
com.my.persistence.repository.ImportRecordRepositorySpec@3bde62ff, testMethod =
$spock_feature_0_0@ImportRecordRepositorySpec, testException =
org.springframework.orm.jpa.JpaSystemException: Unknown unwrap conversion requested:
java.time.OffsetDateTime to [B; nested exception is org.hibernate.HibernateException:
Unknown unwrap conversion requested: java.time.OffsetDateTime to [B,
mergedContextConfiguration = [MergedContextConfiguration@345f69f3 testClass =
ImportRecordRepositorySpec, locations = '{}' , classes = '{ class
com.my.persistence.PersistenceConfiguration}' , contextInitializerClasses =
'[]' , activeProfiles = '{}' , propertySourceLocations = '{}' ,
propertySourceProperties =
'{org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTestContextBootstrapper=
true }' , contextCustomizers =
set[org.spockframework.spring.mock.SpockContextCustomizer@0,
[ImportsContextCustomizer@50de186c key =
[org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,
org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,
org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,
org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration,
org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManagerAutoConfiguration]],
org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@3e2055d6,
org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@50f6ac94,
org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0,
org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@79defdc,
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@351584c0,
org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@f5a8e2f5,
org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@dc9876b,
org.springframework.boot.test.context.SpringBootTestArgs@1], contextLoader =
'org.springframework.boot.test.context.SpringBootContextLoader' , parent = [ null
]], attributes = map[
'org.spockframework.spring.SpringMockTestExecutionListener.MOCKED_BEANS_LIST'
-> list[[empty]]]]
org.springframework.orm.jpa.JpaSystemException: Unknown unwrap conversion requested:
java.time.OffsetDateTime to [B; nested exception is org.hibernate.HibernateException:
Unknown unwrap conversion requested: java.time.OffsetDateTime to [B
at
org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:353)
at
org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:255)
at
org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:528)
at
org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
at
org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
at
org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at
org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:178)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.my.persistence.repository.ImportRecordRepositorySpec.save
entity(ImportRecordRepositorySpec.groovy:38)
Caused by: org.hibernate.HibernateException: Unknown unwrap conversion requested:
java.time.OffsetDateTime to [B
at
org.hibernate.type.descriptor.java.AbstractTypeDescriptor.unknownUnwrap(AbstractTypeDescriptor.java:98)
at
org.hibernate.type.descriptor.java.OffsetDateTimeJavaDescriptor.unwrap(OffsetDateTimeJavaDescriptor.java:98)
at
org.hibernate.type.descriptor.java.OffsetDateTimeJavaDescriptor.unwrap(OffsetDateTimeJavaDescriptor.java:25)
at
org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor$1.doBind(VarbinaryTypeDescriptor.java:45)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:73)
at
org.hibernate.type.descriptor.converter.AttributeConverterSqlTypeDescriptorAdapter$1.bind(AttributeConverterSqlTypeDescriptorAdapter.java:88)
at
org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:276)
at
org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:271)
at
org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:39)
at
org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2929)
at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3226)
at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3760)
at
org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:107)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
at org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:478)
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475)
at
org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:348)
at
org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:57)
at
org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:102)
at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1317)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1397)
at
org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1565)
at
org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1533)
at org.hibernate.query.Query.getResultList(Query.java:165)
at
org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:76)
at
org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:355)
at
org.springframework.data.repository.core.support.ImplementationInvocationMetadata.invoke(ImplementationInvocationMetadata.java:72)
at
org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:382)
at
org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:205)
at
org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:549)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at
org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:155)
at
org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:130)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at
org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:366)
at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at
org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
... 7 more
2020-05-26 21:49:20.517 INFO 9228 --- [extShutdownHook]
j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for
persistence unit ' default '
Using the debugger, I finally ended up in Class
org.hibernate.type.descriptor.sql.JdbcTypeJavaClassMappings, which seems not to define a
Mapping
workMap.put( OffsetDateTime.class, Types.TIMESTAMP );
I have also noted the following log message:
2020-05-26 22:25:07.474 DEBUG 27916 --- [ main]
o.h.cfg.annotations.SimpleValueBinder : Starting fillSimpleValue for importTime
2020-05-26 22:25:07.474 DEBUG 27916 --- [ main]
o.h.cfg.annotations.SimpleValueBinder : Applying JPA AttributeConverter
[org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor@1e471884] to
[com.my.persistence.entity.ImportRecordEntity:importTime]
2020-05-26 22:25:07.476 DEBUG 27916 --- [ main]
o.h.t.d.j.s.JavaTypeDescriptorRegistry : Could not find matching scoped
JavaTypeDescriptor for requested Java class
[com.my.persistence.converter.time.ImportTimeAttributeConverter]; falling back to static
registry
2020-05-26 22:25:07.476 DEBUG 27916 --- [ main]
o.h.t.d.j.s.JavaTypeDescriptorRegistry : Could not find matching scoped
JavaTypeDescriptor for requested Java class [com.my.model.types.history.ImportTime];
falling back to static registry
2020-05-26 22:25:07.476 DEBUG 27916 --- [ main]
o.h.t.d.java.JavaTypeDescriptorRegistry : Could not find matching JavaTypeDescriptor for
requested Java class [com.my.model.types.history.ImportTime]; using fallback. This means
Hibernate does not know how to perform certain basic operations in relation to this Java
type.
2020-05-26 22:25:07.477 DEBUG 27916 --- [ main]
o.h.t.d.j.s.JavaTypeDescriptorRegistry : Could not find matching scoped
JavaTypeDescriptor for requested Java class [java.time.OffsetDateTime]; falling back to
static registry
2020-05-26 22:25:07.477 DEBUG 27916 --- [ main]
o.h.t.d.sql.JdbcTypeJavaClassMappings : JDBC type code mapping not known for class
[java.time.OffsetDateTime]; using custom code [1556520190]
2020-05-26 22:25:07.479 DEBUG 27916 --- [ main]
o.h.t.d.c.AttributeConverterTypeAdapter : Created AttributeConverterTypeAdapter ->
converted::com.my.persistence.converter.time.ImportTimeAttributeConverter
Weird enough, using the OffsetDateTime type directly in the Entity (rather than my hand
craftet ImportRecord) and leaving out the ImportTimeAttributeConverter completely,
everything works fine.
I have also tried to provide yet another AttributeConverter<OffsetDateTime,
Timestamp>, but that didn't change the behaviour (I thought, I might just have to
stack AttributeConverter on top of each other).
Any ideas? Wrong usage or missing setting? Or anything else?
Thanks a lot.
Stefan
(
https://hibernate.atlassian.net/browse/HHH-14042#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-14042#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100127- sha1:dccb6b5 )