MultipleHiLoPerTableGenerator can contain stale hi value, generate duplicate IDs

Description

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.

Environment

Hibernate 3.3.0SP1 on MySQL 5.0.37-community-nt

Activity

Show:
Brett Meyer
March 3, 2014, 3:40 PM

Bulk rejecting issues lacking a test case or recent response.

Brett Meyer
December 19, 2013, 10:31 PM

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!

Brett Meyer
December 12, 2013, 7:23 PM

If this is still an issue in ORM 4.2.x or 4.3, anyone have a test case to attach?

Rejected

Assignee

Unassigned

Reporter

ChrisW

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major