title: JPA primary key value is always 0
body: <p>I have a post class and it kind of works, but there's one problem: the primary key doesn't increase.</p>
  
  <pre><code>@Entity
  @Table(name="posts")
  public class Post extends GenericModel{
  
      @Id
      @Column(name="post_id")
      public int id;
  
      @Column(name="post_situation")
      public String situation;
  
      @Column(name="post_date")
      public Date date;
  
      @Column(name="post_userid")
      public int userid;
  
      @OneToMany(mappedBy="post", cascade=CascadeType.ALL)
      public List&lt;Block&gt; blocks;
  
      public Post addBlock(String content, int position){
          Block b = new Block(this, content, position);
          b.save();
  
          this.blocks.add(b);
  
          this.save();
          return this;
      }
  
      public Post(String situation, Date date){
          this.situation = situation;
          this.date = date;
          this.userid = 2;
      }
  
  }
  </code></pre>
  
  <p>When I call it the first time on an empty table, it works fine, but the second time, I'm getting <code>PersistenceException occured : org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update</code>
  The post_id column always has 0. Any idea how to fix this? I have the @Id annotation in palce..</p>
  
  <p>This is how I have in my controller:</p>
  
  <pre><code>    Post p = new Post("Midden in het middenoosten.", new Date()).save();
  </code></pre>
  
  <p>Any ideas what's causing this problem?</p>