Reputation: 11
I have this tables :
tbShop with fields
tbCategorie with fields
tbCategorieShop using for relation manytomany between tbShop and tbCategorie with fields
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
@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 ?
Upvotes: 1
Views: 430
Reputation: 2592
The issue you are facing is because the field "idAppli" is getting repeated in Shop and Categorie entities. You can mark this field as insertable=false and updatable=false at one of the locations at should fix the issue
Upvotes: 1