So, I just stood up a Spring Hibernate app and I can\'t seem to get my mapping file right. I am using MySql 5 and an auto incrementing key. Here is the ID portion of my mapp
You have to remember that Hibernate is a persistence layer and needs to be able to keep track of where an object is in the database. So when it does an insert, it actually will need to query the auto-increment counter to see what the next ID should be. It then inserts the ID into the object and inserts the object into the database. So for hibernate to do in insert, it uses needs to do a select first (unless you're using some sort of GUID generated by the application). When using mySQL auto-increment, use the "identity" generator.
Explanation of the various generators:
http://www.roseindia.net/hibernate/hibernateidgeneratorelement.shtml
A hibernate XML code snippet:
<id name="id" type="long" unsaved-value="null" >
<column name="uid" not-null="true"/>
<generator class="identity"/>
</id>
"Increment" generator is not cluster friendly. If some other process inserts into the same table. Next insert from hibernate will fail