TableGenerator does not increment hibernate_sequences.next_hi_value anymore after having exhausted the current lo-range

Description

This bug is new in 3.5
In version 3.5 class MultipleHiLoPerTableGenerator.java was modified introducing a
new increment variable
IntegralDataTypeHolder value;
along with
int lo;

The problem in the new code is that only value get's incremented whilst variable lo
is still used to check when a new hiVal must be obtained.

if ( lo > maxLo ) {
IntegralDataTypeHolder hiVal = (IntegralDataTypeHolder) doWorkInNewTransaction( session );

as lo is never incremented, MultipleHiLoPerTableGenerator continues to deliver numbers without ever update
hibernate_sequences.next_hi_value on the database (only one unique update is propagates at the first insert)
This lead to duplicate keys as soon another session from another sessionfactory tries to insert new objects on the concerning table.

Please see attached testcase.
IMPORTANT ADVICE TO RUN THE TESTCASE:
as the testcase uses 2 sessionfactories hibernate.hbm2ddl.auto=create cannot be used!!
Schema has to be exported separately and the testcase must run without hbm2ddl.auto property!

Here the schema for HSQLDB:
create table A (oid bigint not null, name varchar(255), version integer not null, primary key (oid), unique (name))
create table hibernate_sequences ( sequence_name varchar(255), sequence_next_hi_value integer )

Environment

Hibernate: 3.5 , db: HSQLDB (not relevant)

Activity

Show:
Martin Gubser
May 17, 2010, 11:25 PM

Sorry, here are the files

Gail Badner
May 18, 2010, 8:01 PM

Martin, this has been fixed by HHH-5230.

Martin Gubser
May 20, 2010, 2:38 PM

Gail, thanks for you reply. Maybe I do have another problem, but the generator does not work correctly for me: it increments the hi-value when it grabs the first lo-sequence but no more when it grabs further lo-sequences. That error shows only if you run the attached program twice. Setting <property name="hibernate.id.new_generator_mappings">true</property> in my hibernate.cfg.xml does not change this behaviour. Connection.pool_size=4, second-level cache is disabled. Affected versions: 5.1 and 5.2.
Can you run the test program twice without error?

Steve Ebersole
May 20, 2010, 3:22 PM

Martin, you are not using @TableGenerator nor MultipleHiLoPerTableGenerator. You use a @GenericGenerator, naming the "hilo" strategy which maps to TableHiLoGenerator. So if you are having issues with that class, then please open a new issue

Steve Ebersole
May 20, 2010, 3:23 PM

Or switch generators...

Assignee

Steve Ebersole

Reporter

Guenther Demetz

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Critical
Configure