I have three java classes: CommonBon
(parent class), Bon extends CommonBon
and BonHistory extends CommonBon
.
On database side there are two tables: Bon
and BonHistory
. They have different ids(BON_ID
and BON_HISTORY_ID
).
I also have another abstract class CommonProduct
with annotation @MappedSuperclass
which contains:
@OneToMany(mappedBy = "product", cascade = CascadeType.ALL, orphanRemoval = true)
@OrderBy("displayNo")
private Set<CommonBon> bons = new LinkedHashSet<>();
is it technically possible in Hibernate to have @Id
annotation in CommonBon
and somehow override it in two extending classes Bon
and BonHistory
?
I also tried to add @Id
in Bon
and @Id
in BonHistory
and annotate CommonBon
with @MappedSuperclass
but it’s also impossible because then hibernate shout out that I am trying to join @OneToMany
with CommonBon
which is not entity. On the other hand to annotate CommonBon
with @Entity
I need @Id
.
What should be solution for this?
4