title: how to make a composite primary key (java persistence annotation)
body: <p>How to make it so that the table user_roles defines the two columns (userID, roleID) as a composite primary key. should be easy, just can't remember/find.</p>
  
  <p>In <code>user</code> entity:</p>
  
  <pre><code>@ManyToMany(fetch = FetchType.LAZY)
  @JoinTable(name = "user_roles")
  public List&lt;RoleDAO&gt; getRoles() {
      return roles;
  }
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public Integer getUserID() {
      return userID;
  }
  </code></pre>
  
  <p>In <code>roles</code> entity:</p>
  
  <pre><code>@ManyToMany(fetch = FetchType.LAZY)
  @JoinTable(name = "user_roles")
  public List&lt;UserDAO&gt; getUsers() {
      return users;
  }
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public Integer getRoleID() {
      return roleID;
  }
  </code></pre>
  
  <p>Thank you.</p>
  
  <p>** MORE INFO</p>
  
  <p>So there is a third table <code>user_roles</code> (auto generated by above) that takes <code>userID</code> from <code>user</code> entity and <code>roleID</code> from <code>roles</code> entity. Now I need those two columns in the generated table (<code>user_roles</code>) to be a composite primary key.</p>