We're updating the issue view to help you get more done. 

Inherited interfaces are not considered when creating EntityMetamodel

Description

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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:

1 2 3 4 5 6 7 8 9 10 11 12 13 <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:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 } }

Environment

None

Status

Assignee

Chris Cranford

Reporter

Jones

Fix versions

Affects versions

5.0.12
5.1.4
5.2.8

Priority

Major