私はこれらの2つの抽象クラスを持っています:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name="compound")
public abstract class Compound<T extends Containable {
@OneToMany(fetch = FetchType.EAGER, mappedBy="compound",
targetEntity=Containable.class, cascade = CascadeType.ALL)
private Set<T> containables = new HashSet<>();
}
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name="containable")
public abstract class Containable<T extends Compound> {
@ManyToOne(optional=true, fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private T compound;
}
私のテストでは、TestCompound と TestContainable を 1 つのペアとして、RegistrationCompound と Batch をもう 1 つのペアとして、それぞれ 2 つの実装があります。(例:public class TesCompound extends Compound<TestContainable>
およびpublic class RegistrationCompound extends Compound<Batch>
)。
両方の階層の TABLE_PER_CLASS
私が直面している問題は、hibernate が test_containable テーブルから、test_compound ではなく、registration_compound への外部キー制約を作成することです。一般的な関係が得られないようです。
両方の階層で JOINED (私の場合はマイナス面を無視)
ここでは、Compound と Containable が (抽象ではなく) 具象クラスである必要があります。それ以外の場合は同様の問題です。hibernate は、containable -> 複合 (予期される) から外部キー制約を作成しますが、containable -> registration_compound (予期しない) からも外部キー制約を作成します。なぜこれが作成されたのかわかりませんか?さらに紛らわしいのは、containable -> test_compound からのそのような制約がないという事実です。
全体として、非常に混乱しています。single_table を試してみますが、それは最も望ましくないオプションです...