title: EclipseLink how to use two @OneToMany and @ManyToOne to replace @ManyToMany
body: <p>I am new in eclipselink and trying to add extra columns in manyTomany association table.</p>
  
  <p>so i decide to use  two @OneToMany and @ManyToOne to replace @ManyToMany relationship.</p>
  
  <p>i have tried the hibernate way in the following link, but it does't work.
  <a href="http://www.mkyong.com/hibernate/hibernate-many-to-many-example-join-table-extra-column-annotation/" rel="nofollow">http://www.mkyong.com/hibernate/hibernate-many-to-many-example-join-table-extra-column-annotation/</a></p>
  
  <p>Is there anyone know how to build this in eclispelink?</p>
  
  <p>Thanks</p>
  
  <p>-------------------------just follow the link above and paste test code --------------</p>
  
  <p>SideA:</p>
  
  <pre><code>@Entity
  @Table(name = "SideA")
      public class SideA {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private long  id;
  
      private List&lt;ABAssociation&gt; association = new ArrayList&lt;ABAssociation&gt;();
  
  
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.sideA", cascade=CascadeType.ALL)
      public List&lt;ABAssociation&gt; getAssociation() {
            return this.association;
      }
  
      public void setAssociation(List&lt;ABAssociation&gt; association) {
      this.association = association;
      }
  
  }
  </code></pre>
  
  <p>SideB:</p>
  
  <pre><code>@Entity
  @Table(name = "SideB")
  public class SideB {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private long  id;
  
  
      private List&lt;ABAssociation&gt; association = new ArrayList&lt;ABAssociation&gt;();
  
  
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.sideB", cascade=CascadeType.ALL)
      public List&lt;ABAssociation&gt; getAssociation() {
          return this.association;
      }
  
      public void setAssociation(List&lt;ABAssociation&gt; association) {
          this.association = association;
      }
  
  }
  </code></pre>
  
  <p>Associtation:</p>
  
  <pre><code>@Entity
  @Table(name = "ABAssociation")
  @AssociationOverrides({
     @AssociationOverride(name = "pk.sideA", 
      joinColumns = @JoinColumn(name = "SIDEA_ID")),
     @AssociationOverride(name = "pk.sideB", 
      joinColumns = @JoinColumn(name = "SIDEB_ID")) })
  public class ABAssociation {
     private ABAssociationPK pk = new ABAssociationPK();
     @EmbeddedId
     public ABAssociationPK getPk() {
          return pk;
     }
     public void setPk(ABAssociationPK pk) {
         this.pk = pk;
     }
     @Transient
     public SideA getSideA() {
         return getPk().getSideA();
     }
     public void setSideA(SideA sideA) {
         getPk().setSideA(sideA);
     }
     @Transient
     public SideB getSideB() {
         return getPk().getSideB();
     }
     public void setSideB(SideB sideB) {
         getPk().setSideB(sideB);
     } 
     private String extracolumn;
  }
  </code></pre>
  
  <p>ABAssociationPK:</p>
  
  <pre><code>@Embeddable
  public class ABAssociationPK implements java.io.Serializable{
      private static final long serialVersionUID = -3797694126054440157L;
  
      private SideA sideA;
      private SideB sideB;
      public ABAssociationPK(){}
  
      @ManyToOne
      public SideA getSideA() {
          return sideA;
      }
  
      public void setSideA(SideA sideA) {
          this.sideA = sideA;
      }
  
      @ManyToOne
      public SideB getSideB() {
          return sideB;
      }
  
      public void setSideB(SideB sideB) {
          this.sideB = sideB;
      }
  
  }
  </code></pre>
  
  <p>the exception is :<code>Exception Description: Predeployment of PersistenceUnit [testPU] failed.
  Internal Exception: Exception [EclipseLink-7298] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
  Exception Description: The mapping [sideA] from the embedded ID class [class com.fuhu.nabisync.resource.model.entity.ABAssociationPK] is an invalid mapping for this class. An embeddable class that is used with an embedded ID specification (attribute [pk] from the source [class com.fuhu.nabisync.resource.model.entity.ABAssociation]) can only contain basic mappings. Either remove the non basic mapping or change the embedded ID specification on the source to be embedded.</code></p>