我在 id 类中的鉴别器列存在继承问题。该表将成功创建,但每个条目在描述符列中获得“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 {
}
因此,如果我坚持一个新的 Child 类,我希望将“1”作为类型,但我得到“0”。当我从 BasePK 类中删除类型并直接添加到我的 Base 类中时,它可以工作。但是类型应该是键的一部分。
任何帮助将不胜感激。