Jpa 在使用@EmbeddedId的实体上具有简单属性
当我有两个来自其他实体的属性用作实体中的主键时,我可以让这些其他实体实例直接成为实体上的成员:Jpa 在使用@EmbeddedId的实体上具有简单属性,jpa,jpa-2.0,embeddable,Jpa,Jpa 2.0,Embeddable,当我有两个来自其他实体的属性用作实体中的主键时,我可以让这些其他实体实例直接成为实体上的成员: @Entity public class Position { @EmbeddedId private PositionKey positionKey; @MapsId("accountCode") @ManyToOne(fetch = FetchType.LAZY) private Account account; @MapsId("pro
@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属性