IdClass mapped with HBM causes IllegalArgumentException unless hibernate.ejb.metamodel.population=disabled
Description
Activity

Former user May 7, 2018 at 7:39 PM
In 5.1, the failure occurs when an HBM mapping that maps an IdClass is used with EntityManager.
That failure occurs when building the EntityManagerFactory:
javax.persistence.PersistenceException: Unable to build entity manager factory
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:66)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at org.hibernate.bugs.JPAUnitTestCase.init(JPAUnitTestCase.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.IllegalArgumentException: expecting IdClass mapping
at org.hibernate.jpa.internal.metamodel.AttributeFactory$3.resolveMember(AttributeFactory.java:966)
at org.hibernate.jpa.internal.metamodel.AttributeFactory$5.resolveMember(AttributeFactory.java:1024)
at org.hibernate.jpa.internal.metamodel.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:449)
at org.hibernate.jpa.internal.metamodel.AttributeFactory.buildIdAttribute(AttributeFactory.java:128)
at org.hibernate.jpa.internal.metamodel.MetadataContext.buildIdClassAttributes(MetadataContext.java:346)
at org.hibernate.jpa.internal.metamodel.MetadataContext.applyIdMetadata(MetadataContext.java:278)
at org.hibernate.jpa.internal.metamodel.MetadataContext.wrapUp(MetadataContext.java:199)
at org.hibernate.jpa.internal.metamodel.MetamodelImpl.buildMetamodel(MetamodelImpl.java:82)
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:118)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:889)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
... 30 more
An existing test case,
org.hibernate.test.idclass.IdClassTest
, maps an IdClass using an HBM mapping.Specifically, the composite ID with IdClass is mapped as:
There is a comment and JPA metamodel population is disabled:
// the Customer entity has a composite id that is not embeddable ( not supported by JPA ).
configuration.setProperty( AvailableSettings.JPA_METAMODEL_POPULATION, "disabled" );
The comment is incorrect, as the mapping does, in fact, map an ID class:
CustomerId
The IdClass is mapped by:
<composite-id class="CustomerId" mapped="true">
The test only passes because it sets:
hibernate.ejb.metamodel.population=disabled
When the property value is changed to
ignoreUnsupported
orenabled
, the test fails due to: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:182)
at org.hibernate.testing.junit4.TestClassMetadata.performBeforeClassCallbacks(TestClassMetadata.java:173)
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.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.IllegalArgumentException: expecting IdClass mapping
at org.hibernate.metamodel.internal.AttributeFactory$3.resolveMember(AttributeFactory.java:978)
at org.hibernate.metamodel.internal.AttributeFactory$5.resolveMember(AttributeFactory.java:1036)
at org.hibernate.metamodel.internal.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:458)
at org.hibernate.metamodel.internal.AttributeFactory.buildIdAttribute(AttributeFactory.java:128)
at org.hibernate.metamodel.internal.MetadataContext.buildIdClassAttributes(MetadataContext.java:360)
at org.hibernate.metamodel.internal.MetadataContext.applyIdMetadata(MetadataContext.java:290)
at org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:199)
at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:230)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:295)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:461)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:113)
at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:201)
... 15 more