title: Who is responsible of the auto-incrementation of a primary key between MySQL and Hibernate?
body: <p><em>MySQL</em></p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE `role` (
    `id_role` INT(11) unsigned NOT NULL AUTO_INCREMENT,
    PRIMARY KEY (`id_role`)
  ) AUTO_INCREMENT=1;
  </code></pre>
  
  <p><em>Hibernate</em></p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  public class Role {
  
      private Integer idRole;
  
      @Column(name = "id_role", precision = 10)
      @GeneratedValue
      @Id
      public Integer getIdRole() {
          return idRole;
      }
  
      public void setIdRole(Integer idRole) {
          this.idRole = idRole;
      }
  
  }
  </code></pre>
  
  <p>Given the above background, who is responsible of the auto-incrementation of the <code>id_role</code> column when creating a new <code>role</code>? In other words, does Hibernate set the primary key value before running the <code>create</code> SQL statement, or does it set it to <code>null</code> and let MySQL auto-increments the field while getting back the chosen primary key?</p>