title: How to specify JPA join column names?
body: <p>Does anyone know how to specify a specific column name with the following simple example?</p>
  
  <pre><code>@Entity
  public class Role {
      @Id
      @GeneratedValue
      @Column(name="id")
      private final Integer id;
  
      ...
  }
  
  @Entity
  public class User {
      @Id
      @GeneratedValue
      @Column(name="id")
      private final Long id;
  
      @ElementCollection
      @CollectionTable(name = "user_roles" joinColumns = { @JoinColumn(name = "user_id")})
      private final Set&lt;Role&gt; roles;
  
      ...
  }
  </code></pre>
  
  <p>This frustratingly results in a table called "user_roles" and field names: "user_id" and "roles_id".</p>
  
  <p>Why "roles_id" and not "role_id", and how can I change this to "role_id"?</p>
  
  <p>For what it's worth I use JPA 2.0, MySQL and Hibernate. The data I want to add is added correctly, so this is just a matter of taste.</p>
  
  <p>Edit:</p>
  
  <p>The following might be a little bit JPA 1.0'ish, but it works as required.</p>
  
  <pre><code>@ManyToMany
  @JoinTable(name = "user_roles", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
  </code></pre>