Is there a way to override the identifier in a subclass of an object in JPA?

According to a specific requirement, for example, using an abstract base class (or superclass), I need to implement a simple hierarchy of two objects, one of which should distribute the other, but have the other own @Id.

My googling about this seems to be the conclusion that this is not possible or only on condition that I use a matched superclass (which in my case is forbidden due to a specific policy).

I don’t want to duplicate the code of an object with several dozens of attributes, and then mutate the duplicate by adding / redefining attributes to avoid problems with future maintenance, but then I got stuck in the limitations of JPA.

Any help / suggestion would be appreciated.

+2
source share
1 answer

Having different types idfor non-abstract derived objects is not compatible with JPA inheritance strategies.

What I mean:

Imagine that you succeeded, and different classes in the hierarchy use different incompatible types for id.

  • how would you define database restrictions for a single table inheritance in that case?
  • and for joint inheritance?

EDIT: JPA , id. , TABLE_PER_CLASS JPA. , , , .

. , ? . ?

, , , . , , , .

- , A B, 1-1.

, , .

tl; dr , .

+3

All Articles