【发布时间】:2014-12-23 07:49:05
【问题描述】:
我想使用 Hibernate 实体注释从 2 个外键创建一个主键: **
- 如何将这两个外键“comID”和“reference”设为 带有 Hibernate 注释的 LigneCommande 表的主键! 谢谢:)
我试过这段代码,但没有用:
“产品”类:
public class Produit implements Serializable{
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "LigneCommande", catalog = "mkyongdb", joinColumns = {
@JoinColumn(name = "reference", nullable = false, updatable = false) },
inverseJoinColumns = { @JoinColumn(name = "commande_id",
nullable = false, updatable = false) })
private List<Commande> commande;
public List<Commande> getCommande() {
return commande;
}
public void setCommande(List<Commande> commande) {
this.commande = commande;
}
}
“Commande”类:
@Entity
public class Commande implements Serializable{
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "commande")
private List<Produit> produit;
public List<Produit> getProduit() {
return produit;
}
public void setProduit(List<Produit> produit) {
this.produit = produit;
}
}
除此之外我没有任何异常或错误!!
【问题讨论】: