我有一个实体层次结构,它们在根实体中具有必须只读的关系。但是在叶子实体中,这种关系不应该有这种行为。
@Entity
class X {@Id private Long id;} //gets sets
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE")
class Root {
@Id private Long id; //gets sets
@ManyToOne
@JoinColumn(name = "X_ID", nullable = false, insertable = false, updatable = false) //READ ONLY
private X x;
}
@Entity
@DiscriminatorValue(value = "ExampleValue")
@AssociationOverrides({ //I try to override to becomes no longer read only
@AssociationOverride(name = "x", joinColumns = {@JoinColumn(name = "X_ID", referencedColumnName = "X_ID" nullable = false)}
}
class Leaf extends Root {
}
但是当我在Leaf对象中调用实体管理器时,生成的sql不包含X_ID列信息。
答案 0 :(得分:0)
替换此
@Entity
@DiscriminatorValue(value = "ExampleValue")
@AssociationOverrides({ //I try to override to becomes no longer read only
@AssociationOverride(name = "x", joinColumns = {@JoinColumn(name = "X_ID", referencedColumnName = "X_ID" nullable = false)}
}
class Leaf extends Root {
}
与
@Entity
@DiscriminatorValue(value = "ExampleValue")
@Table(name = "LEAF")
public class Leaf
{
@Embedded
@AssociationOverrides({
@AssociationOverride(name = "x", joinColumns = {@JoinColumn(referencedColumnName = "X_ID" nullable = false)})
private Root root;
}