AbstractClass - Employee - Engineer (および他の多くのサブクラス) などのクラスの階層があり、クラス階層戦略ごとに単一のテーブルを使用します。AbstractClass にはプロパティがありcase
、定義した従業員には@DiscriminatorFormula("case")
、エンジニアにはいくつかの があり@DiscriminatorValue
ます。
すべてのオブジェクトを HQL-query でロードするとSELECT id FROM Employee
、Hibernate は次の SQL クエリを作成します。
select employee0_.id as col_0_0_ from public.tbl_employee employee0_ where employee0_.case in ('engineer', 'operator')
つまり、Hibernate はすべての識別子の値に冗長な制限を追加します。
この IN 制限を SQL から除外する方法はありますか?
AbstractClass と Employee の簡略化されたマッピングがいくつかあります。
@MappedSuperclass
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class AbstractClass {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN")
@SequenceGenerator(name = "SEQ_GEN", sequenceName = "objectid_sequence", allocationSize = 100)
private long id;
@Column(name = "case", nullable = false)
private String case;
}
@Entity
@Table(name = "tbl_employee")
@DiscriminatorFormula("case")
public class Employee extends AbstractClass {
@Column(name = "name", nullable = false)
private String name = "";
}