title: Hibernate auto_increment MySQL
body: <p>I am using Eclipse, Xammp (tomcat and MySQL DB) and Hibernate.</p>
  
  <p>this all works good, but I can't create that the ID from the Entity will be <code>auto_increment</code> in the Database</p>
  
  <p>My Entity:</p>
  
  <pre><code>package com.jwt.hibernate.bean;
  
  
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  
  import org.hibernate.annotations.GenericGenerator;
  
  
  
  @Entity
  public class User {
  
      @Id
      @GenericGenerator(name="generator", strategy="increment")
      @GeneratedValue(generator="generator")
      private Long userId;
      private String userName;
      private String password1;
      private String email;
      private String phone;
      private String city;
  
  
      public Long getUserId() {
          return userId;
      }
  
  
      public void setUserId(Long userId) {
          this.userId = userId;
      }
  
  
      public String getUserName() {
          return userName;
      }
  
  
      public void setUserName(String userName) {
          this.userName = userName;
      }
  
      public String getPassword1() {
          return password1;
      }
  
      public void setPassword1(String password1) {
          this.password1 = password1;
      }
  
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      public String getPhone() {
          return phone;
      }
  
      public void setPhone(String phone) {
          this.phone = phone;
      }
  
      public String getCity() {
          return city;
      }
  
      public void setCity(String city) {
          this.city = city;
      }
  }
  </code></pre>
  
  <p>I create a hbm.xml for this Entity with a Plugin from Hibernate and use <code>Hibernate XML Mapping file(hbm.xml)</code>:
  Created hbm.xml:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  &lt;!-- Generated 06.05.2016 11:59:26 by Hibernate Tools 3.5.0.Final --&gt;
  &lt;hibernate-mapping&gt;
      &lt;class name="com.jwt.hibernate.bean.User" table="USER"&gt;
          &lt;id name="userId" type="java.lang.Long"&gt;
              &lt;column name="USERID" /&gt;
              &lt;generator class="assigned" /&gt;
          &lt;/id&gt;
          &lt;property name="userName" type="java.lang.String"&gt;
              &lt;column name="USERNAME" /&gt;
          &lt;/property&gt;
          &lt;property name="password1" type="java.lang.String"&gt;
              &lt;column name="PASSWORD1" /&gt;
          &lt;/property&gt;
          &lt;property name="email" type="java.lang.String"&gt;
              &lt;column name="EMAIL" /&gt;
          &lt;/property&gt;
          &lt;property name="phone" type="java.lang.String"&gt;
              &lt;column name="PHONE" /&gt;
          &lt;/property&gt;
          &lt;property name="city" type="java.lang.String"&gt;
              &lt;column name="CITY" /&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>My hibernate.cfg.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/test&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
          &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
          &lt;property name="hbm2ddl.auto"&gt;create-drop&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
          &lt;mapping resource="/com/jwt/hibernate/bean/User.hbm.xml" /&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>If i start my Code, the Console do:</p>
  
  <pre><code>Hibernate: drop table if exists USER
  Hibernate: create table USER (USERID bigint not null, USERNAME varchar(255), PASSWORD1 varchar(255), EMAIL varchar(255), PHONE varchar(255), CITY varchar(255), primary key (USERID))
  </code></pre>
  
  <p>Every thing  is fine but my ID isn't <code>auto_increment</code> and I don't know why.
  I tried a lot of Annotations.
  other Annotations for Example <code>ManyToMany</code> or <code>ManyToOne</code> works, but nut the <code>@GeneratedValue</code></p>