title: Hibernate: duplicate key value violates unique constraint
body: <p>I am trying to insert into a new record to my postgresql using Hibernate and Java EE.</p>
  
  <p>This is my model:</p>
  
  <pre><code>@Entity
  @SuppressWarnings("serial")
  @Inheritance(strategy=InheritanceType.JOINED)
  public class BaseDesign implements Serializable {
  
      @Id
      @Expose
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id", updatable = false, nullable = false)
      private Long id;
  
      @Version
      @Column(name = "version")
      private int version;
  
      @Expose
      @Column(name = "name")
      private String name;
  
      // getter and setter
  }
  </code></pre>
  
  <p>And here is my import.sql</p>
  
  <pre><code>INSERT INTO basedesign (id, name, version) VALUES (1, 'China', 0);
  </code></pre>
  
  <p>When I build the code, the record is added into db.</p>
  
  <p>However, when I try to add a new record using EntityManager, like this:</p>
  
  <pre><code>BaseDesign design = new BaseDesign();
  design.setName("USA");                  
  em.persist(design);
  </code></pre>
  
  <p>I got: </p>
  
  <pre><code>Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "basedesign_pkey"
    Detail: Key (id)=(1) already exists.
  </code></pre>
  
  <p>Execute the same command for second time, and it success.</p>
  
  <p>Why do Hibernate not increment the starting ID at the first time? And how to configure it to start at the last inserted integer?</p>