title: Hibernate declare composite primary key in JoinTable (List<>)
body: <hr>
  
  <h2>Hibernate declare composite primary key in JoinTable (List&lt;>)</h2>
  
  <hr>
  
  <p>How do I declare the composite primary key in a side table using HQL (Hibernate query language)? Previously I got one jointable declared in my class and everything worked fine, it created a composite primary key of the two columns. This is the code I used: <br></p>
  
  <p><strong>BEFORE (worked)</strong></p>
  
  <pre><code>@Id
  @SequenceGenerator(name="someSequence", sequenceName="SEQ_APP", allocationSize =1)
  @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="appSequence")
  @Column(name="id")
  private int setting_id;
  
  @OneToOne
  private User user;
  
  @ManyToMany
  @JoinTable(
          name="tbl_settings_objectproxy",
          joinColumns = @JoinColumn(name = "id"),
          inverseJoinColumns = @JoinColumn( name = "objectproxy_id")
  )
  private Set&lt;SomeObject&gt; objectproxy;
  </code></pre>
  
  <p>Now I scrued everything up, I changed the Set to a List and added another side table. Now hibernate creates two side tables as it is supposed to do but it doesn't declare any primary key's... does anyone know how to fix this?  This is my new code:<br></p>
  
  <p><strong>AFTER (it doesn't create composite primary key anymore, it doesn't even declare any primary key)</strong></p>
  
  <pre><code>@Id
  @SequenceGenerator(name="someSequence", sequenceName="SEQ_APP", allocationSize =1)
  @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="appSequence")
  @Column(name="id")
  private int setting_id;
  
  @OneToOne
  private User user;
  
  
  @ManyToMany
  @JoinTable(
      name="tbl_settings_objectproxy",
      joinColumns = @JoinColumn(name = "id"),
      inverseJoinColumns = @JoinColumn( name = "objectproxy_id")
      )
  private List&lt;SomeObject&gt; objectProxyForSomething;
  </code></pre>