相关疑难解决方法(0)

Embeddable类中的外键映射

我使用eclipselinkJPA.我有一个实体,它有一个由两个字段组成的复合键.以下是我的可嵌入主键类'字段(成员).

    @Embeddable
    public class LeavePK {
       @ManyToOne(optional = false)
       @JoinColumn(name = "staffId", nullable = false)
       private Staff staff;
       @Temporal(TemporalType.TIMESTAMP)
       private Calendar date;
       //setters and getters
    }
Run Code Online (Sandbox Code Playgroud)

我的实体将保留与员工相关的休假数据,因此我尝试将员工对象和离开日期结合起来以生成组合键.除了我的逻辑,它不允许我在embeddable类中有一个外键映射.当我尝试使用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 …
Run Code Online (Sandbox Code Playgroud)

java entity-relationship jpa composite-key embeddable

12
推荐指数
1
解决办法
2万
查看次数