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
This also affects org.hibernate.test.criteria.CriteriaQueryTest.testMultiplePropertiesSubquery
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.
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.