Issues

Select view

Select search mode

 
50 of 106

Cannot override non-identifier propety from @MappedSuperclass and make it identifier in subclass

Description

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 - 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?

Attachments

1
  • 19 Sep 2022, 03:59 PM

Details

Assignee

Reporter

Components

Affects versions

Priority

Created September 19, 2022 at 3:59 PM
Updated September 26, 2022 at 11:35 AM

Activity

Show:

Flag notifications