[JIRA] (HHH-16784) @MappedSuperclass with parameterized types does not work in 6.x (works with 5.x)
by László Mórocz (JIRA)
László Mórocz ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYWMyZGYwYjJj... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16784?atlOrigin=eyJpIjoiYWMyZG... ) HHH-16784 ( https://hibernate.atlassian.net/browse/HHH-16784?atlOrigin=eyJpIjoiYWMyZG... ) @MappedSuperclass with parameterized types does not work in 6.x (works with 5.x) ( https://hibernate.atlassian.net/browse/HHH-16784?atlOrigin=eyJpIjoiYWMyZG... )
Issue Type: Bug Affects Versions: 6.2.4 Assignee: Unassigned Attachments: hibernate-orm-5-TemporalAccessor.zip, hibernate-orm-6-TemporalAccessor.zip Components: hibernate-core Created: 12/Jun/2023 09:17 AM Environment: 6.2.4.Final (also with 6.2.2.Final), Priority: Major Reporter: László Mórocz ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... )
With the Spring Boot 3.1.0 upgrade we're also upgrading to Hibernate 6(.2.2.Final - as of Spring Boot 3.1.0 BOM). We have an abstract (audited entity super) class with @MappedSuperclass annotation and (Spring Data's) AuditingEntityListener. This class has a T extends java.time.temporal.TemporalAccessor type parameter for the createTime and updateTime fields.
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class AbstractJpaAuditedEntity<I extends Serializable, U, T extends TemporalAccessor> implements Serializable, HasJpaAuditing<U, T> {
[...]
I is for the entity ID type, U is for the create/updateUser field type.
We have several subclasses (as concrete JPA entities), for example:
@Entity
public class TestEntity extends AbstractJpaAuditedEntity< Long , String , LocalDateTime> {
[...]
This structure works well with Hibernate 5.x (and Spring Boot 2). Now, after the Spring Boot 3 + Hibernate 6 upgrade the app doesn't start anymore:
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-06-12T16:47:36.799+02:00 ERROR 5040 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: [PersistenceUnit: default ] Unable to build Hibernate SessionFactory; nested exception is java.lang.IllegalArgumentException: Named type [ interface java.time.temporal.TemporalAccessor] did not implement BasicType nor UserType
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770) ~[spring-beans-6.0.9.jar:6.0.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598) ~[spring-beans-6.0.9.jar:6.0.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[spring-beans-6.0.9.jar:6.0.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.9.jar:6.0.9]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.9.jar:6.0.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.9.jar:6.0.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.9.jar:6.0.9]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1156) ~[spring-context-6.0.9.jar:6.0.9]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:931) ~[spring-context-6.0.9.jar:6.0.9]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608) ~[spring-context-6.0.9.jar:6.0.9]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:733) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:435) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1305) ~[spring-boot-3.1.0.jar:3.1.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1294) ~[spring-boot-3.1.0.jar:3.1.0]
at hu.rr.lea.boot3demoapp.Boot3demoAppApplication.main(Boot3demoAppApplication.java:35) ~[classes/:na]
Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: default ] Unable to build Hibernate SessionFactory; nested exception is java.lang.IllegalArgumentException: Named type [ interface java.time.temporal.TemporalAccessor] did not implement BasicType nor UserType
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:421) ~[spring-orm-6.0.9.jar:6.0.9]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-6.0.9.jar:6.0.9]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352) ~[spring-orm-6.0.9.jar:6.0.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1816) ~[spring-beans-6.0.9.jar:6.0.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766) ~[spring-beans-6.0.9.jar:6.0.9]
... 16 common frames omitted
Caused by: java.lang.IllegalArgumentException: Named type [ interface java.time.temporal.TemporalAccessor] did not implement BasicType nor UserType
at org.hibernate.boot.model.TypeDefinition.createResolution(TypeDefinition.java:235) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.boot.model.TypeDefinition.createResolution(TypeDefinition.java:124) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.boot.model.TypeDefinition.resolve(TypeDefinition.java:109) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.mapping.BasicValue.interpretExplicitlyNamedType(BasicValue.java:663) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.mapping.BasicValue.buildResolution(BasicValue.java:374) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.mapping.BasicValue.resolve(BasicValue.java:310) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.mapping.BasicValue.getType(BasicValue.java:288) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.metamodel.internal.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:407) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:115) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:100) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:332) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl.processJpa(JpaMetamodelImpl.java:531) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.finishInitialization(MappingMetamodelImpl.java:213) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.internal.SessionFactoryImpl.initializeMappingModel(SessionFactoryImpl.java:319) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:269) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:431) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1455) ~[hibernate-core-6.2.2.Final.jar:6.2.2.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:66) ~[spring-orm-6.0.9.jar:6.0.9]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:376) ~[spring-orm-6.0.9.jar:6.0.9]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-6.0.9.jar:6.0.9]
... 20 common frames omitted
I attached two reproducer test projects based on the hibernate-test-case-templates ( https://github.com/hibernate/hibernate-test-case-templates/tree/main ) repo (without Spring Boot, and Spring Data dependencies):
* hibernate-orm-5-TemporalAccessor.zip - working as intended
* hibernate-orm-6-TemporalAccessor.zip - produces Exception (with Hibernate 6.2.2 or 6.2.4) in org.hibernate.testing.junit4.BaseCoreFunctionalTestCase#buildSessionFactory()
org.hibernate.testing.junit4.CallbackException: org.hibernate.testing.junit4.BaseCoreFunctionalTestCase#buildSessionFactory
at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:204)
at org.hibernate.testing.junit4.TestClassMetadata.invokeCallback(TestClassMetadata.java:188)
at org.hibernate.testing.junit4.TestClassMetadata.performCallbacks(TestClassMetadata.java:180)
at org.hibernate.testing.junit4.TestClassMetadata.performBeforeClassCallbacks(TestClassMetadata.java:171)
at org.hibernate.testing.junit4.BeforeClassCallbackHandler.evaluate(BeforeClassCallbackHandler.java:25)
at org.hibernate.testing.junit4.AfterClassCallbackHandler.evaluate(AfterClassCallbackHandler.java:25)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.lang.IllegalArgumentException: Named type [ interface java.time.temporal.TemporalAccessor] did not implement BasicType nor UserType
at org.hibernate.boot.model.TypeDefinition.createResolution(TypeDefinition.java:235)
at org.hibernate.boot.model.TypeDefinition.createResolution(TypeDefinition.java:124)
at org.hibernate.boot.model.TypeDefinition.resolve(TypeDefinition.java:109)
at org.hibernate.mapping.BasicValue.interpretExplicitlyNamedType(BasicValue.java:663)
at org.hibernate.mapping.BasicValue.buildResolution(BasicValue.java:374)
at org.hibernate.mapping.BasicValue.resolve(BasicValue.java:310)
at org.hibernate.mapping.BasicValue.getType(BasicValue.java:288)
at org.hibernate.metamodel.internal.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:409)
at org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:115)
at org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:100)
at org.hibernate.metamodel.internal.MetadataContext.buildAttribute(MetadataContext.java:278)
at org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:362)
at org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl.processJpa(JpaMetamodelImpl.java:531)
at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.finishInitialization(MappingMetamodelImpl.java:213)
at org.hibernate.internal.SessionFactoryImpl.initializeMappingModel(SessionFactoryImpl.java:320)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:270)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:431)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:894)
at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:129)
at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:114)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:201)
... 14 more
Maybe this is related to HHH-16122 ( https://hibernate.atlassian.net/browse/HHH-16122 ) Closed. Please have a look, thanks.
( https://hibernate.atlassian.net/browse/HHH-16784#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16784#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=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100225- sha1:956085d )
1 year, 3 months