An instance of MultipleHiLoPerTableGenerator seems to be created per table (and per schema?). This instance seems to persist across DB sessions/transactions, retaining the "hi" value that it last loaded from the generator table. The problem comes when the generator retains this "hi" value across a DB reset. It is not unusual to reinitialize a schema for a new customer, or to restore a backup dump. The problem is that when a DB is reset, this "hi" value is no longer valid, causing the IDs to wrap around and eventually duplicate. Example sequence:
generate ID 195
generate ID 196
<DB reset.>
generate ID 197
generate ID 198
generate ID 199
<max lo reached. Load new "hi" value from DB.>
generate ID 1
generate ID 2
... (etc) ...
generate ID 196
generate ID 197 (ID is now duplicated, causing NonUniqueObjectException)
Perhaps the generator can recheck the generator table at the beginning of a transaction to ensure its hi value is consistent.
Hibernate 3.3.0SP1 on MySQL 5.0.37-community-nt
If this is still an issue in ORM 4.2.x or 4.3, anyone have a test case to attach?
Note: In an attempt to clean up the HHH JIRA, we will be rejecting any ticket that sits in the "Awaiting Test Case" state for 2-3 months with no response. So, if this issue is critical to you, please attach a reproducing test case ASAP. Thanks!
Bulk rejecting issues lacking a test case or recent response.