I am using hibernate’s “increment” generator to generate my auto increment Id’s. This was working fine until I had to add another application which also uses the “increment” generator to generate new id’s. I realised there is a catch with the increment generator:
"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."
Is there any way to deal with this using hibernate? Or will I have to write additional code to lock the table, check the db for max Id (and then increment it) and finally release the lock? Using one hibernate configuration is not an option. Also I can not add the auto_increment option to the db table because we have more than one key on the table.
Any suggestions are welcome, I am guessing this is a common problem.
There are several other generators which may give you what you need:
I’d recommend taking a look at hi/lo.
I find this statement confusing – you cannot have one column be auto-incrementing if the primary key of the table uses more than one column?
Why would you have a primary key of more than one column where one of the columns is unique anyway – this makes it impossible to ever have more than one value for the
idfield, thus negating the purpose of a compound PK.