title: How to map an auto increment field in hibernate?
body: <p>Please have a look at the below XML code</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;
  &lt;!-- Generated Feb 17, 2015 10:01:43 PM by Hibernate Tools 4.3.1 --&gt;
  &lt;hibernate-mapping&gt;
      &lt;class name="model.main.Family" table="family" catalog="****" optimistic-lock="version"&gt;
          &lt;id name="idFamily" type="int"&gt;
              &lt;column name="idFamily" /&gt;
              &lt;generator class="assigned" /&gt;
          &lt;/id&gt;
          &lt;many-to-one name="employee" class="model.main.Employee" fetch="select"&gt;
              &lt;column name="idEmployee" not-null="true" /&gt;
          &lt;/many-to-one&gt;
          &lt;property name="firstName" type="string"&gt;
              &lt;column name="FirstName" length="45" /&gt;
          &lt;/property&gt;
          &lt;property name="middleName" type="string"&gt;
              &lt;column name="MiddleName" length="45" /&gt;
          &lt;/property&gt;
          &lt;property name="lastName" type="string"&gt;
              &lt;column name="LastName" length="45" /&gt;
          &lt;/property&gt;
          &lt;property name="dob" type="date"&gt;
              &lt;column name="DOB" length="10" /&gt;
          &lt;/property&gt;
          &lt;property name="passportNumber" type="string"&gt;
              &lt;column name="PassportNumber" length="45" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="dateLeft" type="date"&gt;
              &lt;column name="DateLeft" length="10" /&gt;
          &lt;/property&gt;
          &lt;property name="lastUpdated" type="timestamp"&gt;
              &lt;column name="LastUpdated" length="19" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;set name="visas" table="visa" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="idFamily" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="model.main.Visa" /&gt;
          &lt;/set&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>It is the <code>Hibernate</code> mapping class of my database table <code>Family</code>. We create the database separately using MySQL Work bench and then generate the mapping classes. We auto generated the mapping files using netbeans as mentioned in <strong><em>"Generating Hibernate Mapping Files and Java Classes"</em></strong> section of <a href="https://netbeans.org/kb/docs/web/hibernate-webapp.html" rel="nofollow">netbeans tutorial</a>.</p>
  
  <p>Now we have a problem. That is, we changed the <code>primary key</code> (<code>idFamily</code>) of our table <code>Family</code> to an <code>auto generated</code> field inside MySQL. Now, how can we change the above hibernate code so it identifies the <code>idFamily</code> as an auto generated one?</p>
  
  <p>The other question is, manually editing one mapping class without regenerating all the mappings via a tool can "break" the system? For an example, like messing up with relationships?</p>