我想設置我的實體允許PKS。我的數據庫包含兩個字段,Hibernate的JPA多對一複合鍵
dealer_detail_id PK user_detail_id PK
無論是在相應的表上的ID加入。
迄今沒有成功,我已經試過這一點。
@Embeddable
public class DealerUserPk implements Serializable {
private Integer dealerDetail;
private Integer userDetail;
DealerUser
@Embeddable
@Table(name = "dealer_user", schema = "account")
public class DealerUser implements Serializable {
@EmbeddedId
private DealerUserPk id;
@Id
@ManyToOne
@JoinColumn(name = "dealer_detail_id", referencedColumnName = "id")
private DealerDetail dealerDetail;
@Id
@ManyToOne
@JoinColumn(name = "user_detail_id", referencedColumnName = "id")
private UserDetail userDetail;
DealerDetail
@Entity
@Table(name = "dealer_detail", schema = "account")
public class DealerDetail implements Serializable {
@Id
private Integer id;
UserDetail
@Entity
@Table(name = "user_detail", schema = "account")
public class UserDetail implements Serializable {
@Id
private Integer id;
任何人能發現我在做什麼錯?
我沒有看到任何生成錯誤,但是當我對錶運行以下查詢時,我得到零結果列表 dealerUsers = session.createCriteria(DealerUser.class).list(); –
我最終只是錯過了@Entity。 –