SQLServer2012Dialect creates sequences starting from Long.MIN_VALUE

Description

on MSSQL2012 creates a sequence of type bigint, starting by default from the number -9,223,372,036,854,775,808. It would make much more sense to start with 1, as other dialects do.

Furthermore, this number is exactly equal to java's Long.MIN_VALUE, so it confuses the IdentifierGeneratorHelper$BasicHolder which then thinks it hasn't been initialized and throws IdentifierGenerationException from the makeValue() method. This means the default hibernate_sequence becomes unusable

To reproduce, run org.hibernate.test.id.SequenceGeneratorTest against a SQL Server 2012 database. It will fail with

Environment

None

Activity

Show:
Gail Badner
May 14, 2014, 5:04 AM

This also affects org.hibernate.test.criteria.CriteriaQueryTest.testMultiplePropertiesSubquery

Gail Badner
May 14, 2014, 7:28 AM
Edited

There are 2 ways to deal with this when using an HBM mapping file:
1) use ID generator, org.hibernate.id.enhanced.SequenceStyleGenerator, instead of "sequence"; org.hibernate.id.enhanced.SequenceStyleGenerator initializes the sequence to 1.
2) add a parameter with an initial value, for example:

I changed SequenceGeneratorTest so it will be skipped for SQLServer2012Dialect; instead I added SQLServer2012SequenceGeneratorTest with a mapping that provides an initial value as above. I also changed the mapping for CriteriaQueryTest to use org.hibernate.id.enhanced.SequenceStyleGenerator instead of "sequence" (since the type of sequence is not relevant to the test).

I've pushed this to 4.2 and 4.3. Using <generator class="org.hibernate.id.enhanced.SequenceStyleGenerator" /> is currently broken in master, so I haven't pushed this to master yet.

Gail Badner
May 14, 2014, 11:58 PM

I've renamed SQLServer2012SequenceGeneratorTest to SequenceGeneratorWithInitialValueTest for master branch because currently parameters are ignored when mapped for "sequence" generator in HBM mapping. That bug is covered by HHH-9189.

Assignee

Gail Badner

Reporter

Jan Martiška

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure