Uploaded image for project: 'Hibernate ORM'
  1. HHH-11554

Inherited interfaces are not considered when creating EntityMetamodel

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.0.12, 5.1.4, 5.2.8
    • Fix Version/s: 5.2.9
    • Component/s: None
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true

      Description

      Migrating from hibernate 4.3 to hibernate 5.2.8.Final I encountered the following issue:

      Fatal error org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [META-INF/spring/jpa.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: appPersistenceUnit] Unable to build Hibernate SessionFactory
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
      	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
      	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)
      	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
      	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
      	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
      	...
      Caused by: javax.persistence.PersistenceException: [PersistenceUnit: appPersistenceUnit] Unable to build Hibernate SessionFactory
      	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:967)
      	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:892)
      	at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:151)
      	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
      	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373)
      	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
      	... 15 more
      Caused by: org.hibernate.PropertyNotFoundException: Could not locate getter method for property [com.myentity.MyEntity#id]
      	at org.hibernate.internal.util.ReflectHelper.findGetterMethod(ReflectHelper.java:420)
      	at org.hibernate.property.access.internal.PropertyAccessBasicImpl.<init>(PropertyAccessBasicImpl.java:41)
      	at org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl.buildPropertyAccess(PropertyAccessStrategyBasicImpl.java:27)
      	at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:322)
      	at org.hibernate.tuple.PropertyFactory.buildIdentifierAttribute(PropertyFactory.java:63)
      	at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:135)
      	at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:519)
      	at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:124)
      	at sun.reflect.GeneratedConstructorAccessor146.newInstance(Unknown Source)
      	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
      	at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96)
      	at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
      	at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:128)
      	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:297)
      	at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
      	at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:889)
      

      The hibernate mapping is done using hbm.xml files:

      	<class name="com.myentity.MyEntity" table="MY_ENTITY" abstract="true" discriminator-value="null">
      		<cache usage="transactional"/>
      		<id name="id" column="ID" access="property" type="NumericInteger">
      			<generator class="com.mygenerator.MyIdGenerator">
      				<param name="segment_value">MyEntity</param>
      			</generator>
      		</id>
      		<discriminator column="TYPE" type="big_integer" force="true" />
      	</class>
      
      	<subclass name="com.myentity.MyRealEntity" extends="com.myentity.MyEntity" discriminator-value="1" lazy="false">
      		...
      	</subclass>
      

      MyRealEntity implements MyEntity interface.
      MyEntity interface extends Common interface
      Common interface extends Entity interface
      Entity interface has getId() and setId(...)

      Please find a unit test with the issue:

      import org.hibernate.internal.util.ReflectHelper;
      import org.junit.Test;
      
      public class ReflectHelperTest {
      
          interface A {
      
              String getId();
          }
      
          interface B extends A {
      
              Integer getFoo();
          }
      
          interface C extends B {
      
              String getBar();
          }
      
          @Test
          public void testSimpleInheritance() {
              ReflectHelper.findGetterMethod(B.class, "id"); // this works
          }
      
          @Test
          public void testIndirectInheritance() {
              ReflectHelper.findGetterMethod(C.class, "id"); // this doesn't work
          }
      
      }
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: