2

idクラスの識別子列に継承の問題があります。テーブルは正常に作成されますが、各エントリはdescriminator列に「0」の値を取得します。

これが私の基本クラスです:

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER)
@IdClass(BasePK.class)
@SuppressWarnings("serial")
public abstract class Base implements Serializable {

@Id
protected Test test;

@Id
protected Test2 test2;

@Id
private int type;

....
}

これが私の基本pkクラスです:

@Embeddable
public static class BasePK implements Serializable {

@ManyToOne
protected Test test;

@ManyToOne
protected Test2 test2;

@Column(nullable = false)
protected int type;

...
}

そして、私はこのようないくつかのサブクラスを持っています:

@Entity
@DiscriminatorValue("1")
@SuppressWarnings("serial")
public class Child extends Base {

}

したがって、新しい子クラスを永続化すると、タイプとして「1」が期待されますが、「0」になります。BasePKクラスからタイプを削除し、Baseクラスに直接追加すると機能します。ただし、タイプはキーの一部である必要があります。

どんな助けでも大歓迎です。

4

1 に答える 1

1

私はいくつかの変更を加えました、

それらが同一だったので、私は余分な埋め込み可能なクラスをスキップしました。

アノテーションと子クラスのコンストラクターで型の値を設定する必要がありました。そうしないと、Hibernateセッションが同じ値を持つ異なるクラスを処理できませんでした(NotUniqueObjectExceptionが発生しました)。

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER)
@IdClass(Base.class)
public abstract class Base implements Serializable {
    @Id @ManyToOne protected Test test;
    @Id @ManyToOne protected Test2 test2;
    @Id private int type;
}

@Entity
@DiscriminatorValue("1")
public class Child1 extends Base {
    public Child1(){
        type=1;
    }
}

@Entity
@DiscriminatorValue("2")
public class Child2 extends Base {
    public Child2(){
        type=2;
    }
}
于 2012-12-14T17:24:02.887 に答える