嵌入式类中的外键映射
2022-09-04 02:29:09
我正在使用 .我有一个实体,它有一个由两个字段构成的复合密钥。以下是我的嵌入式主键类的字段(成员)。eclipselink
JPA
@Embeddable
public class LeavePK {
@ManyToOne(optional = false)
@JoinColumn(name = "staffId", nullable = false)
private Staff staff;
@Temporal(TemporalType.TIMESTAMP)
private Calendar date;
//setters and getters
}
我的实体将保存与员工相关的休假数据,因此我尝试将员工对象和休假日期组合在一起以生成复合键。除了我的逻辑之外,它不允许我在嵌入式类中有一个外键映射。当我尝试使用JPA工具时 - >从实体生成表,它给出了如下错误,这解释了,但我没有得到它。
org.eclipse.persistence.exceptions.ValidationException
Exception Description: The mapping [staff] from the embedded ID class [class rs.stapp.entity.LeavePK] is an invalid mapping for this class. An embeddable class that is used with an embedded ID specification (attribute [leavePK] from the source [class rs.stapp.entity.Leave]) can only contain basic mappings. Either remove the non basic mapping or change the embedded ID specification on the source to be embedded.
这是否意味着,我不能有一个键(来自复合键),它也是一个外键。有没有另一种方法可以完成此 ERM?请帮忙。谢谢