JPA Inheritance IdClass Best Practice

Where to define @IdClassannotation in both scenarios?


In my view for case 1: both Entity1 and Entity2 should have their own @IdClass.

since Entity2 also has a primary key.


and for case 2: MapedSuperClass2 should have @IdClass.

since both Entity1 and Entity2 use the same primary key.


I'm right?

Case 1:

enter image description here

Case 2:

enter image description here

+3
source share
1 answer

In the first scenario, when you define an IdClass in a parent class, you cannot add or even delete key fields in subclasses, so adding a new value to a key in Entity2 is not allowed by the specification.

@IdClass MapperSuperClass, , , , .

0

All Articles