[英]java hibernate @ManyToMany with composite key and common field org.hibernate.MappingException: Repeated column in mapping for collection
I have this tables : 我有这张桌子:
tbShop with fields 带有字段的tbShop
tbCategorie with fields tbCategorie与字段
tbCategorieShop using for relation manytomany between tbShop and tbCategorie with fields tbCategorieShop用于在tbShop和tbCategorie之间使用字段进行多对关系
Entity Shop : 实体店:
@Entity
@Table(name = "tbShop")
public class Shop implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected ShopPK shopPK;
@Column(name = "commNom")
private String name;
@ManyToMany( fetch=FetchType.EAGER)
@Cascade({CascadeType.SAVE_UPDATE, CascadeType.ALL})
@JoinTable(name = "tbCategorieShop",
joinColumns = {
@JoinColumn(name = "idAppli", referencedColumnName = "idAppli")
, @JoinColumn(name = "idShop", referencedColumnName = "idShop")}
, inverseJoinColumns = {
@JoinColumn(name = "idCategorie", referencedColumnName = "idCategorie")
, @JoinColumn(name = "idAppli", referencedColumnName = "idAppli")}
)
private List<Categorie> tbCategorie ;
Entity Categorie: 实体类别:
@Entity
@Table(name = "tbCategorie")
public class Categorie implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected CategoriePK categoriePK;
@Column(name = "categName")
private String categName;
@JoinTable(name = "tbCategorieShop", joinColumns = {
@JoinColumn(name = "idCategorie", referencedColumnName = "idCategorie")
, @JoinColumn(name = "idAppli", referencedColumnName = "idAppli")}
, inverseJoinColumns = {
@JoinColumn(name = "idAppli", referencedColumnName = "idAppli")
, @JoinColumn(name = "idShop", referencedColumnName = "idShop")}
)
@ManyToMany
private Collection<Shop> shopCollection;
...
Primary Key ShopPk 主键ShopPk
@Embeddable
public class ShopPK implements Serializable {
@Basic(optional = false)
@Column(name = "idAppli")
private int idAppli;
@Basic(optional = false)
@Column(name = "idShop")
private String idShop;
... }
Primary Key CategoriePk 主键分类
@Embeddable
public class CategoriePK implements Serializable {
@Basic(optional = false)
@Column(name = "idCategorie")
private int idCategorie;
@Basic(optional = false)
@Column(name = "idAppli")
private int idAppli;
and I have error 我有错误
Caused by: org.hibernate.MappingException: Repeated column in mapping for collection: hello.Categorie.shopCollection column: id_appli
Is it possible to have common field in this entites for ManyToMany relation ? 在这个与ManyToMany关系中的实体中是否可能有共同的领域?
The issue you are facing is because the field "idAppli" is getting repeated in Shop and Categorie entities. 您面临的问题是因为Shop和Categorie实体中的“ idAppli”字段越来越多。 You can mark this field as insertable=false and updatable=false at one of the locations at should fix the issue
您可以在以下位置之一将此字段标记为insertable = false和updatable = false,以解决此问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.