title: How to create 3 or 4 way many-to-many association mapped as Entity class in JPA 2
body: <p>am working with spring 3.1, hibernate 4.0.1.FINAL, and spring-data-jpa 1.0.2.RELEASE. So let's say i have a <code>many-to-many</code> between <code>class A</code> and <code>class B</code> that i mapped as <code>ABMap</code>. I also have another many-to-many between <code>class C</code>  and <code>class D</code> mapped as <code>CDMap</code>.
   i have a class <code>ABMapID</code> annotated @Embeddable </p>
  
  <pre><code>@Embeddable
  public class ABMapID{
     private String aID;
     private String bID;
  }
  //... setters and getters
  </code></pre>
  
  <p>so the mapping itself is below</p>
  
  <pre><code> @Entity
   public class ABMap {
  
   @Id
  @AttributeOverrides({
    @AttributeOverride(name = "aID", column = @Column(name = "a_id",insertable = false, updatable = false)),
    @AttributeOverride(name = "bID", column = @Column(name = "b_id", insertable = false,updatable = false))
  })
  private ABMapID ID;
  @ManyToOne(targetEntity = A.class)
  @JoinColumn(name = "a_id",insertable = false,updatable = false)
  private A a;
  
  @ManyToOne(targetEntity = B.class)
  @JoinColumn(name = "b_id", insertable = false, updatable = false)
  private B b;
  //.... setters and getters  
  }
  </code></pre>
  
  <p>Now let's say we want to change the <code>ABMap</code> to <code>ACDMap</code> where the <code>ACDMapID</code> is made up with aID, and CDMapID(which itself is made up with cID,dID).
  so my new association id is  ACDMapID</p>
  
  <pre><code> @Embeddable
   public class ACDMapID {
    private String aID;
    private CDMapID cdmapID;
  
  } 
  
  and the entity is mapped like so
  
  @Entity
  public class ACDMap {
     @Id
  @AttributeOverrides({
    @AttributeOverride(name = "aID", column = @Column(name = "a_id",insertable = false, updatable = false)),
    @AttributeOverride(name = "cdmapID", column = @Column(name = "dcmap_id", insertable = false,updatable = false))
  })
    private ACDMapID ID;
  
  }
  </code></pre>
  
  <p>So running this give me this error </p>
  
  <blockquote>
    <p>Caused by: org.hibernate.AnnotationException: A Foreign key refering CDMap from ACDMap has the wrong number of column. should be 2</p>
  </blockquote>
  
  <p>is there a way to do that mapping ? preferable i would like to keep CDMap as such.</p>