rampatel
rampatel

Reputation: 541

hibernate generator increment conflict with table auto increment

I set generator as 'increment' in hbm file, and also i put auto_increment thing in database table also. This creteria showing issue ....

This both thing is conflicting ? ?

Upvotes: 1

Views: 4105

Answers (1)

Joel Hudon
Joel Hudon

Reputation: 3205

Yes they are conflicting, makes no sense..

When using hibernate built-in generator 'increment', it's hibernate that generate the identifiers by counting from the maximum primary key value at startup, not safe in multi JVM and using the database AUTO_INCREMENT it's the database that generate a unique identity for new rows.

In mySQL DB, if using AUTO_INCREMENT you should use identity in your mapping to let the database safely generate unique identity.

From hibernate documentation

increment

Generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. Do not use in a cluster.

identity

supports identity columns in DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL. The returned identifier is of type long, short or int.

More information
Hibernate Doc section 5.1.4.1. Generator
My sql AUTO_INCREMENT documentation

Upvotes: 3

Related Questions