0

スーパークラスといくつかの子クラス (以下を参照) を持つこのタイプの JPA エンティティ設定がある場合、各子クラスの最初の 3 つ (作成日順) を選択する JPA クエリをどのように作成しますか? 2 つの別個のクエリを作成し、特定のサブクラスを要求することは問題なく機能しますが、可能であれば 1 つのクエリにまとめたいと考えています。

@MappedSuperclass
public class Parent {
    @Temporal(TIMESTAMP)
    @Column(name = "created")
    private Date created;
    ...
}

@Entity
@DiscriminatorValue("A")
public class ChildA extends Parent {
    ...
}

@Entity
@DiscriminatorValue("B")
public class ChildB extends Parent {
    ...
}
4

2 に答える 2

0

継承を実現する@Inheritance(strategy = InheritanceType.SINGLE_TABLE) には、識別子列で使用できます...

@MappedSuperclass: "... 継承するエンティティにマッピング情報が適用されるクラスを指定します ..."

http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html_single/#mapping-declarationを参照

これを行った後、次のようなクエリを簡単に作成できますSELECT p from Parent p order by p.created...

于 2014-09-23T09:40:16.237 に答える