title: JPA 2.0 many-to-many with extra column
body: <p>I'm trying to do a ManyToMany relationship in JPA 2.0 (JBoss 7.1.1) with an extra column (in bold, below) in the relationship, like:</p>
  
  <pre><code>Employer           EmployerDeliveryAgent             DeliveryAgent
  (id,...)   (employer_id, deliveryAgent_id, **ref**)  (id,...)
  </code></pre>
  
  <p>I wouldn't like to have duplicate attributes, so I would like to apply the second solution presented in <a href="http://giannigar.wordpress.com/2009/09/04/mapping-a-many-to-many-join-table-with-extra-column-using-jpa/" rel="noreferrer">http://giannigar.wordpress.com/2009/09/04/mapping-a-many-to-many-join-table-with-extra-column-using-jpa/</a> . But I can't get it to work, I get several errors like:</p>
  
  <ol>
  <li>Embedded ID class should not contain relationship mappings (in fact the spec says so);</li>
  <li>In attribute 'employerDeliveryAgent', the "mapped by" value 'pk.deliveryAgent' cannot be resolved to an attribute on the target entity;</li>
  <li>In attribute 'employerDeliveryAgent', the "mapped by" value 'pk.employer' cannot be resolved to an attribute on the target entity;</li>
  <li>Persistent type of override attribute "pk.deliveryAgent" cannot be resolved;</li>
  <li>Persistent type of override attribute "pk.employer" cannot be resolved;</li>
  </ol>
  
  <p>Many people on that link said that it worked fine, so I suppose something is different in my environment, perhaps JPA or Hibernate version. So my question is: how do I achieve such scenario with JPA 2.0 (Jboss 7.1.1 / using Hibernate as JPA implementation)? And to complement that question: should I avoid using composite keys and instead use plain generated id and a unique constraint?</p>
  
  <p>Thanks in advance.</p>
  
  <p>Obs.: I didn't copy my source code here because it is essentially a copy of the one at the link above, just with different classes and attributes names, so I guess it is not necessary.</p>