title: JPA: Modelling m:n relationship & join-table values
body: <p>having a m:n real-world relationship between some entities, e.g. user &lt;---> group
  Now I want to model this relationship and store additional information based on it, e.g. a field "quality".</p>
  
  <p>I heard that I would have to create a new join table user_group as follows:</p>
  
  <pre><code>id | user_ref | group_ref | quality
  ----------------------------------
  1      1           1         0.5
  2      1           2         1.3
  ...    ...         ...        ...
  </code></pre>
  
  <p>The corresponding entity has two related entities (private members) user and group, annotated with the <strong>@ManyToOne</strong>-annotation.
  On the other hand, both, my user and my group have a set of related user_group-entities, both private members and declared with the <strong>@OneToMany</strong>-annotation.</p>
  
  <p>I have three questions:</p>
  
  <ol>
  <li>Is this the right way to model the problem of additional fields in JPA 2.0? </li>
  <li>I not allowed to use both user and group in user_group as primary key
  since they are not valid primary key types. Is it really necessary to declare a new primary.</li>
  <li>Is this a common workflow with these join-tables/entities?</li>
  </ol>
  
  <p>...</p>
  
  <pre><code>EntityManager em = ...
  ...
  em.getTransaction().begin();
  User u = new User("Pete");
  Group g = new Group("Anonymous workaholics")
  UserGroup ug = new UserGroup();
  ug.addUser(u);
  ug.addGroup(g);
  
  em.persist(u); em.persist(g); em.persist(ug);
  em.getTransaction().commit();
  em.close()
  </code></pre>
  
  <p>Thanks a lot!</p>