@IdClass with @MappedSuperclass results in "property not found"

Description

If class heirarchy defines a IdClass with a property in the @MappedSuperclass and a property in the @Entity class, the entity manager throws an AnnotationException:

Caused by: org.hibernate.AnnotationException: Property of @IdClass not found in entity com.jpabugreport.Employee: ssn
at org.hibernate.cfg.AnnotationBinder.fillComponent(AnnotationBinder.java:2603)
at org.hibernate.cfg.AnnotationBinder.bindIdClass(AnnotationBinder.java:2716)
at org.hibernate.cfg.AnnotationBinder.mapAsIdClass(AnnotationBinder.java:1041)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:781)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3788)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3742)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
... 49 more

This issue is mentioned by others here: http://stackoverflow.com/questions/4216102/composite-key-in-jpa-hibernate-with-inherited-class

Attached is test project to reproduce issue

Attachments

1

Activity

Show:

Chris Cranford February 28, 2017 at 3:35 AM

I stumbled onto this problem while working on building a test case for HHH-11508.
PR added and ready for review.

Steve Ebersole October 28, 2015 at 3:24 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Steve Ebersole October 27, 2015 at 7:16 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/

Hendy Irawan August 19, 2014 at 11:57 AM
Edited

BTW, the workaround has a nasty side-effect (HHH-9350) when used with schema generation, it generates duplicate composite columns:

I tried to not use @MappedSuperclass at all, but the wrong schema generation still happens. BTW I'm using DefaultComponentSafeNamingStrategy which may be where the bug lies. This is probably a different bug, asked in http://stackoverflow.com/questions/16335513/hibernate-find-with-composite-key-invalid-column-name-exception

The proper workaround involves adding @Column(name=) manually, which works well with schema generation:

Hendy Irawan August 19, 2014 at 7:17 AM
Edited

The mentioned workaround works, by adding to TwitterListedCount : (note that both @Id *and* @Type must be added for user types to still work)

FYI, when used together with Spring Data, it's required to remove the @Id *and* @Type annotations from the MappedSuperclass. If these are not removed, there will be errors bellow. It doesn't change the nature of this Hibernate bug, BTW.

Fixed

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

Priority

Created April 10, 2014 at 5:55 AM
Updated March 16, 2017 at 12:54 PM
Resolved February 28, 2017 at 4:22 PM