JohannesMartin (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNDQ2YjJlYjg3...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-15529?atlOrigin=eyJpIjoiNDQ2Yj...
) HHH-15529 (
https://hibernate.atlassian.net/browse/HHH-15529?atlOrigin=eyJpIjoiNDQ2Yj...
) Cannot override non-identifier propety from @MappedSuperclass and make it identifier in
subclass (
https://hibernate.atlassian.net/browse/HHH-15529?atlOrigin=eyJpIjoiNDQ2Yj...
)
Issue Type: Bug Affects Versions: 5.0.9, 5.6.11, 5.3.28 Assignee: Unassigned Attachments:
HHH-xxxxx-MappedSuperclassAndId.zip Components: metamodel Created: 19/Sep/2022 08:59 AM
Environment: hibernate-entitymanager (versions see about)
OpenJDK 8
Ubuntu 20.04
MySQL Priority: Major Reporter: JohannesMartin (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
I’ve got a @MappedSuperClass A defining field testA as non-identifier. Class B extends
Class A, defining additional field testB. Class B annotates both field testA and field
testB with @Id.
At runtime, hibernate 5.6.11 complains:
org.hibernate.MappingException: You cannot override the [testA] non-identifier property
from the [sample.entities.A] base class or @MappedSuperclass and make it an identifier in
the [sample.entities.B] subclass!
Earlier versions just silently ignore the @Id annotation on testA.
If I annotate testA as @Id in the MappedSuperclass, the code runs fine, but this violates
JPA spec (JPA 2.1
http://download.oracle.com/otndocs/jcp/persistence-2_1-fr-eval-spec (
http://download.oracle.com/otndocs/jcp/persistence-2_1-fr-eval-spec ) - Chapter 2.4):
The primary key must be defined on the entity class that is the root of
the entity hierarchy or on a mapped superclass that is a (direct or
indirect) superclass of all entity classes in the entity hierarchy. The
primary key must be defined exactly once in an entity hierarchy.
Why does hibernate handle things like this? Is there a way around it.
(
https://hibernate.atlassian.net/browse/HHH-15529#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15529#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100207- sha1:7afd384 )