title: Hibernate not respecting MySQL auto_increment primary key field
body: <p>I am trying to learn how Hibernate works, and I am running into an almost unacceptable learning curve. I can't see how to get Hibernate to respect the auto_increment policy for my objects. Instead, it is overwriting entries in the database with existing IDs, beginning with 1.</p>
  
  <p>I have a simple <code>Foo</code> object, backed by a MySQL table defined like this:</p>
  
  <pre><code>CREATE TABLE `Foo` (
    `fooId` int(11) NOT NULL AUTO_INCREMENT,
    PRIMARY KEY (`fooId`),
  )
  </code></pre>
  
  <p>I have confirmed that inserting multiple Foo objects by hand with SQL (<code>insert into Foo values();</code>) does the right thing.</p>
  
  <p>My Java class has the ID specified using annotations like this:</p>
  
  <pre><code>@Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  @Column(name="fooId")
  private Integer id;
  </code></pre>
  
  <p>I then execute some test code that simply instantiates Foo objects and saves them to the database (using <code>session.save(obj)</code>). It seems that it uses its own primary key sequence, beginning with one, and does not look at the table's key policy. It overwrites whatever was there.</p>
  
  <p>I have tried variations on the <code>@GeneratedValue</code> bit (using all possible strategies, leaving off the parenthetic clause). Somebody even suggested leaving off the <code>GeneratedValue</code> entirely. Nothing seems to work. </p>
  
  <p>Am I leaving something out? What am I missing? Is Hibernate really this hard?</p>
  
  <p>(If anybody has an alternative Java database persistence option, please suggest one. I am making prototypes, not long-lasting mondo-engineered projects.)</p>