Attribute in metamodel is null for overridden property

Description

If a property of an entity is overridden in an extending class the corresponding attribute of the metamodel of the extending class is not initialized. It stays null.
I am overridden the getter to add validation constraints.
I extended the MappedSuperclassWithAttributesTest test to show the problem.
We migrated from Wildfly 8.2 (Hibernate 4.3.11) to Wildfly 10.1 (Hibernate 5.0.10).
With Hibernate 4.3.11 the attribute of the metamodel was not null.
PR with test case will follow.

See also: https://forum.hibernate.org/viewtopic.php?f=1&t=1043571

Environment

None

Activity

Show:
Oliver Breidenbach
September 1, 2016, 2:57 PM

Added PR with Testcase.

Gail Badner
September 2, 2016, 9:19 PM
Edited

In 4.2, I get the exception:
javax.persistence.PersistenceException: Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:925)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:900)
at org.hibernate.ejb.test.metagen.mappedsuperclass.attribute.MappedSuperclassWithAttributesTest.testStaticMetamodelOverridden(MappedSuperclassWithAttributesTest.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:63)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62)
Caused by: org.hibernate.MappingException: Duplicate property mapping of overridenName found in org.hibernate.ejb.test.metagen.mappedsuperclass.attribute.Product
at org.hibernate.mapping.PersistentClass.checkPropertyDuplication(PersistentClass.java:502)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:492)
at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1329)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
... 13 more

I get a very similar exception on 4.3 branch.

Oliver Breidenbach
September 5, 2016, 4:10 PM

Sorry my mistake, thank you for hint. I over simplified the testcase. I altered the PR to respect our real situation.

We have 3 levels of entity classes. In the class where we are overridding the attribute, we have the following annotation.

without that in 4.3.11 we got an exception:

Assignee

Unassigned

Reporter

Oliver Breidenbach

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Affects versions

Priority

Minor
Configure