title: Many to Many relationship with attributes Hibernate Annotations (Repeated Column ?)
body: <p>I was trying to figure out how to configure a many to many relationship using JPA annotations and Hibernate, i read many articles and forum discussions, but I end up with an error.</p>
  
  <p>First thing i wanted to know is how:
  <strong>Configure a many to many relationship with attributes</strong></p>
  
  <p>I have two tables <strong>Equipements</strong> and <strong>Maintenance_Companies</strong> and the relation <strong>Reparation</strong> </p>
  
  <p>When i add an entity for the relationship and make some @OneToMany in the others, i had that problem with composed primary key, so i used the Collection approach but i have that exception:</p>
  
  <p><code>org.hibernate.MappingException: Repeated column in mapping for collection: mmapp.domain.Equipement.reparations column: EQUIPEMENT_FK</code></p>
  
  <p>the equipement:</p>
  
  <pre><code>@Entity
  @Table( name = "EQUIPEMENTS" )
  public class Equipement implements Serializable{
  
  private int id ;
  private String marque ;
  private int isbn ;
  private Date purchaseDate ;
  private double price ;
  private int warrantyPeriod ;
  
  public Equipement(){
  }
  
  public Equipement( String marque ) {
      this.marque = marque ;
  }
  
  @Id
  @GeneratedValue( strategy = GenerationType.AUTO )
  @Column( name = "EQUIPEMENT_ID" )
  public int getId(){
      return this.id ;
  }
  
  public void setId(int id){
      this.id = id ;
  }
  
  @Column( name = "EQUIPEMENT_MARQUE" )
  public String getMarque(){
      return this.marque ;
  }
  
  public void setMarque(String marque){
      this.marque = marque ;
  }
  
  @Column( name = "EQUIPEMENT_PUR_DATE" )
  public Date getPurchaseDate(){
      return this.purchaseDate ;
  }
  
  public void setPurchaseDate(Date purchaseDate){
      this.purchaseDate = purchaseDate ;
  }
  
  @Column( name = "EQUIPEMENT_PRICE" )
  public double getPrice(){
      return this.price ;
  }
  
  public void setPrice(double price){
      this.price = price ;
  }
  
  @ElementCollection
  @JoinTable(
      name= "EQUIPEMENT_MAINTENANCE_COMPANY" ,
      joinColumns=@JoinColumn( name= "EQUIPEMENT_FK" ))
  public Collection&lt;Reparation&gt; getReparations() {
      return reparations ;
  }
  
  public void setReparations(Collection&lt;Reparation&gt; reparations) {
      this.reparations = reparations ;
  }
  
  private Collection&lt;Reparation&gt; reparations ;
  
  }
  </code></pre>
  
  <p>the Maintenance Company:</p>
  
  <pre><code>@Entity
  @Table( name = "MAINTENANCE_COMPANIES" )
  public class MaintenanceCompany implements Serializable{
  
  private int id ;
  private String name ;
  private String adress ;
  private String telephone ;
  
  public MaintenanceCompany(){}
  
  public MaintenanceCompany( String name ) {
      this.name = name ;
  }
  
  public void setId(int id){
      this.id = id ;
  }
  
  @Id
  @GeneratedValue( strategy = GenerationType.AUTO )
  public int getId(){
      return this.id ;
  }
  
  public void setName(String name){
      this.name = name ;
  }
  
  public String getName(){
      return this.name ;
  }
  
  public void setAdress(String adress){
      this.adress = adress ;
  }
  
  public String getAdress(){
      return this.adress ;
  }
  
  public void setTelephone(String telephone){
      this.telephone = telephone ;
  }
  
  public String getTelephone(){
      return this.telephone ;
  }
  
  @ElementCollection
  @JoinTable(
      name= "EQUIPEMENT_MAINTENANCE_COMPANY" ,
      joinColumns=@JoinColumn( name= "COMPANY_FK" ))
  public Collection&lt;Reparation&gt; getReparations(){
      return reparations ;
  }
  
  public void setReparations(Collection&lt;Reparation&gt; reparations){
      this.reparations = reparations ;
  }
  
  private Collection&lt;Reparation&gt; reparations ;
  
  }
  </code></pre>
  
  <p>the Reparation</p>
  
  <pre><code>@Embeddable
  public class Reparation implements Serializable{
  
  private int delay ;
  private double price ;
  private Date date ;
  
  public Reparation() {} 
  
  public Reparation(int delay, double price, Date date) {
      this.delay = delay ;
      this.price = price ;
      this.date = date ;
  }
  
  public int getDelay() {
      return delay ;
  }
  
  public void setDelay( int delay ) {
      this.delay = delay ;
  }
  
  public double getPrice() {
      return price ;
  }
  
  public void setPrice( double price ) {
      this.price = price ;
  }
  
  public Date getDate() {
      return date ;
  }
  
  public void setDate( Date date ) {
      this.date = date ;
  }
  
  @ManyToOne( fetch = FetchType.LAZY )
  @JoinColumn( name = "EQUIPEMENT_FK" )
  public Equipement getEquipementRepared(){
      return equipementRepared ;
  }
  
  
  public void setEquipementRepared(Equipement equipementRepared) {
      this.equipementRepared = equipementRepared ;
  }
  
  private Equipement equipementRepared ;
  
  @ManyToOne( fetch = FetchType.LAZY )
  @JoinColumn( name = "COMPANY_FK" )
  public MaintenanceCompany getMaintenanceCompany() {
      return maintenanceCompany ;
  }
  
  public void setMaintenanceCompany( MaintenanceCompany maintenanceCompany ) {
      this.maintenanceCompany = maintenanceCompany ;
  }
  
  private MaintenanceCompany maintenanceCompany ;
  }
  </code></pre>