Inheritance JOINED with two entity mapped in same table


Here is the class model, namely that we can reference either ActorEcore or Actor which forces me to define them both as @Entity.
The problem is that by doing this, as the two tables are persisted in the same table I have this error:

org.hibernate.AnnotationException: Foreign key circularity dependency involving the following tables: TACTEUR, TACTEUR

Here he proposes to change the inheritance strategy to SINGLE_TABLE and to use @SecondaryTable but it is not very simple because it forces to redefine all the attributes to declare the secondary table used


@Table(name = "TACTEUR")
@Inheritance(strategy = JOINED)
@DiscriminatorColumn(name = "ROLE", length = 80)
public abstract class ActeurEcore

public abstract class Acteur extends ActeurEcore

@Table(name = "TPERSONNEMORALE")
public abstract class PersonneMorale extends Acteur

@Table(name = "TAGENCEBANCAIRE")
@GenerationParameter(value = "")
public class AgenceBancaire extends PersonneMorale

You could try to map Acteur as @MappedSuperclass instead if you really need that class.

The problem if I convert to @MappedSuperClass I can no longer reference the Actor class.
I had tried this already.
The error: @entity Actor not found

I left with the solution of the SINGLE_TABLE strategy using the @SecondaryTable annotation.
It’s not more elegant but it seems to work.
I have to redefine everywhere on all the attributes of the child classes the secondary table with @Column (table = “secondTable”)

1 Like

Thanks for your answer, it help me a lot :wink: !

1 Like