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|smart-link] - Chapter 2.4):
{quote}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.{quote}
Why does hibernate handle things like this? Is there a way around it.? |
|