title: JPA - One to many - duplicate key value error
body: <p>I need implement join table for users which will have 2 columns <code>USER_CONTACTS(user_id, contact_id)</code></p>
  
  <p>I need store for contacts lists for users. I need to make possible that user with id 1 can have in contacts user with id 5, but user 5 can also have in contacts user with id 1 (but he musn't).</p>
  
  <p>I need to be possible do following inserts:</p>
  
  <pre><code>INSERT INTO USERS_CONTACTS(user_id, contact_id) VALUES(1, 5);
  INSERT INTO USERS_CONTACTS(user_id, contact_id) VALUES(5, 1);
  </code></pre>
  
  <p>Now I got this error:</p>
  
  <blockquote>
    <p>Unsuccessful: INSERT INTO USERS_CONTACTS(user_id, contact_id)
    VALUES(2, 3) 2017-12-05 15:00:15.146 ERROR 14268 --- [           main]
    org.hibernate.tool.hbm2ddl.SchemaExport  : ERROR: duplicate key value
    violates unique constraint "uk_j9ggomsdbjte1eqfo5e61vh8a"</p>
  </blockquote>
  
  <p>Here is my relationship implementation of User in JPA:</p>
  
  <pre><code>@Entity
  public class User{
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "ID", columnDefinition = "serial")
      private long id;
  
      @OneToMany
      @JoinTable(name = "USERS_CONTACTS",
              joinColumns = @JoinColumn(name = "USER_ID"),
              inverseJoinColumns = @JoinColumn(name = "CONTACT_ID"))
      private List&lt;User&gt; contacts;
  
     // ...
  }
  </code></pre>
  
  <p>Can you tell me how to fix it? I am using Postgre 9.5. Thanks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>For hibernate I have these properties:</p>
  
  <pre><code>spring.jpa.show-sql = true
  spring.jpa.hibernate.ddl-auto = create-drop
  spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
  spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
  spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
  </code></pre>