0

Let "A" be a base entity with TABLE_PER_CLASS inheritance strategy. Let "B" and "C" be entity subclasses of "A". let "D" be an entity that has a @ManyToOne relationship to "A". let "A" have a @OneToMany relationship to "D". Entity classes are given below:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class A {
    @Id
    @GeneratedValue(strategy = SEQUENCE, generator = "a_sequence_generator")
    @SequenceGenerator(name = "a_sequence_generator", sequenceName = "sequence_a")
    @Column(name = "id", nullable = false, unique = true)
    private Long id;

    @OneToMany(mappedBy = "a")
    private List<D> dlist;
    
    // other fields and methods
}

@Entity
public class B extends A {
    // fields and methods specific to B
}

@Entity
public class C extends A {
    // fields and methods specific to C
}

@Entity
public class D {
    @ManyToOne
    @JoinColumn(name = "a_id")
    private A a;
    
    // other fields and methods
}

What should the change-sets look like for tables "A", "B", "C" and "D" in that case? What confuses me is the @ManyToOne mapping. Since @JoinColumn is used, "a_id" must be a valid column, which means that "A" table needs to be created even though it can never be instantiated.

Can we avoid creating the "A" table?

  • This is a JPA question: "Which tables JPA expects to map these entities to?". I suggest to use "hibernate.hbm2ddl.auto=update" property (or other) to let the JPA provider automatically create the tables, then to use Liquibase "generate" comand to produce the changeset. Than you can set the property to "none" (or remove it altogheter). – CT Liv Apr 16 '23 at 13:25

0 Answers0