我有以下实体:
@Entity
@IdClass(IntegrationMappingPK.class)
public class IntegrationMapping {
@Id
@ManyToOne
private IntegrationProject project;
@Id
private String mappingName;
...
}
@Entity
public class MappingElement extends FlowElement {
@ManyToOne(cascade=CascadeType.PERSIST)
@PrimaryKeyJoinColumns({
@PrimaryKeyJoinColumn(name="DISCOVERY_ID", referencedColumnName="DISCOVERY_ID"),
@PrimaryKeyJoinColumn(name="SCENARIONAME", referencedColumnName="SCENARIONAME"),
@PrimaryKeyJoinColumn(name="PROJECTNAME", referencedColumnName="PROJECTNAME"),
})
@JoinColumn(name="MAPPINGNAME", referencedColumnName="MAPPINGNAME")
private IntegrationMapping mapping;
...
}
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@IdClass(FlowElementPK.class)
public class FlowElement {
@Id
@ManyToOne
protected IFlow flow;
@Id
@Basic
protected String name;
@Id
@GeneratedValue
private int id;
...
}
IntegrationMapping和FlowElement共享主键字段“DISCOVERY_ID”、“SCENARIONAME”和“PROJECTNAME”(本质上是IntegrationProject的PK;IFlow有一个由IntegrationProject的PK和一个Name组成的主键),所以它们是Joined。
我让 Hibernate 在启动时从实体创建表。这样做时,FLOWELEMENT 表中缺少列“MAPPINGNAME”。
我也尝试使用@PrimaryKeyJoinColumn,这会导致创建列,但尽管变量不是空的。
执行此操作的正确方法是哪种(@JoinColumn 或 @PrimaryKeyJoinColumn),为什么未创建/填充列?