In database we have a "parent" table with a discriminator column, and depending on this discriminator column some columns are stored in specific tables or some relationships (many/one-to-many) are allowed.
In our mapping we wanted to implement it like
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class A {
@Id
@Column
private int id;
}
@Entity
public class B extends A {
@Column
private String specificField;
}
@Entity
public class C extends A {
@OneToMany
private List<OtherEntity> otherEntities;
}
Unfortunately Hibernate wants to join on table C, which does not exist since it would only contain the FK to A. Is there a way to keep this strategy but tell that no join is necessary?
Otherwise, what is the cleanest solution? Following this question I thought using the SINGLE_TABLE
strategy with the @SecondaryTable
annotation on child entities that require it but it seems heavier to configure (having to declare, for each column, the source table).