如何解决使用@EmbeddedId对实体具有简单属性
当我拥有其他实体的两个属性作为实体的主键时,我可以让其他实体实例直接成为该实体的成员:
@Entity
public class Position {
@EmbeddedId
private PositionKey positionKey;
@MapsId("accountCode")
@ManyToOne(fetch = FetchType.LAZY)
private Account account;
@MapsId("productId")
@ManyToOne(fetch = FetchType.LAZY)
private Product product;
}
@Embeddable
public class PositionKey {
private String accountCode
private Logn productId;
}
现在,假设嵌入的id是两种简单的类型:
@Entity
public class Position {
@EmbeddedId
private PositionKey positionKey;
// how can I have this here? @MapsId doesn't work
private String accountCode;
// how can I have this here? @MapsId doesn't work
private Integer productId;
}
@Embeddable
public class PositionKey {
private String accountCode
private Long productId;
}
使用@EmbeddedId,是否可以在Position类上具有accountCode和productId属性?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。