Duplicate Property with AccessType.PROPERTY and MappedSuperclass

Description

We have the following class hierarchy:
entity A extends from B (mapped superclass).
AccessType is PROPERTY.

class A defines a method getTest() which is overriden in class B.

This causes the following exception:

Caused by: org.hibernate.MappingException: Duplicate property mapping of testA found in sample.entities.B
at org.hibernate.mapping.PersistentClass.checkPropertyDuplication(PersistentClass.java:515)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:505)
at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1360)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1851)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:85

the attached zip contain a testcase.

Environment

all

Activity

Show:
JohannesMartin
May 3, 2016, 11:09 AM

Steve's patch applies almost cleanly to Hibernate 4.2.23, so I was able to integrate it into JBoss 7 by backporting it and replacing the bundled version of Hibernate in JBoss with the patched version of Hibernate 4.2.23.

JohannesMartin
May 2, 2016, 12:01 PM

Steve, I just realized the test case I ran within JBoss was slightly different than the one posted here. I did not specify an AccessType on my entity, and appearently it defaulted to AccessType.FIELD. Also, my error message was different:
java.sql.SQLException: Invalid column index
I can replicate that error message with the attached test case when annotating class B with @Access(AccessType.FIELD).

This might explain, why you were not able to verify that the code worked with older versions of hibernate, it might only have worked with AccessType.FIELD. Luckily, your fix solves both cases, with Hibernate 5.0.9 the test case succeeds with both AccessTypes.

Now my only problem is that I cannot get Hibernate 5 to work within JBoss 7 (class mismatches during startup prevent UserTypes from being applied...).

Steve Ebersole
February 23, 2016, 6:34 PM

Like I said, I was not able to get this to work with annotations using any versions of Hibernate. And I went back pretty far. I went back as far as org.hibernate:hibernate-entitymanager:3.2.0.ga which is even further back than you use. And in no version I tried did this ever work.

Anyway, I fixed it yesterday. GIve it is a try. The solution is not ideal, but I think it is the best we can do until I get the time to completely revamp annotation binding.

Johannes Martin
February 19, 2016, 7:57 AM

We use the artifacts that came bundled with JBoss 4.2.2. Then manifest of hibernate-entitymanager says:

The one from hibernate3:

hibernate-annotations is:

Steve Ebersole
February 17, 2016, 12:55 AM

For the extends-Entity case.. ah right... because the Subclass sees the column with the same name from the RootClass. Fundamentally its the same issue. In both cases we process the attribute from both the super and sub. The difference is just that we don't model MappedSuperclass "inline" with the PersistentClass hierarchy so that Property literally gets duplicated into each sub (hence the dup Property exception).

Fixed

Assignee

Steve Ebersole

Reporter

Jakob Braeuchi

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major