HHH-11456 - SequenceHiLoGeneratorTest fails due to wrong select string on SQL Server
(cherry picked from commit e46956b0f1
)
Conflicts:
hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java
This commit is contained in:
parent
5f68b9a906
commit
91e478a460
|
@ -89,34 +89,35 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
|
|||
@Test
|
||||
public void testHiLoAlgorithm() {
|
||||
sessionImpl = (SessionImpl) sessionFactory.openSession();
|
||||
try {
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// historically the hilo generators skipped the initial block of values;
|
||||
// so the first generated id value is maxlo + 1, here be 4
|
||||
assertEquals(4L, generateValue());
|
||||
// which should also perform the first read on the sequence which should set it to its "start with" value (1)
|
||||
assertEquals(1L, extractSequenceValue());
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// historically the hilo generators skipped the initial block of values;
|
||||
// so the first generated id value is maxlo + 1, here be 4
|
||||
assertEquals( 4L, generateValue() );
|
||||
// which should also perform the first read on the sequence which should set it to its "start with" value (1)
|
||||
assertEquals( 1L, extractSequenceValue() );
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals(5L, generateValue());
|
||||
assertEquals(1L, extractSequenceValue());
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 5L, generateValue() );
|
||||
assertEquals( 1L, extractSequenceValue() );
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals(6L, generateValue());
|
||||
assertEquals(1L, extractSequenceValue());
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 6L, generateValue() );
|
||||
assertEquals( 1L, extractSequenceValue() );
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals(7L, generateValue());
|
||||
// unlike the newer strategies, the db value will not get update here. It gets updated on the next invocation
|
||||
// afterQuery a clock over
|
||||
assertEquals(1L, extractSequenceValue());
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 7L, generateValue() );
|
||||
// unlike the newer strategies, the db value will not get update here. It gets updated on the next invocation
|
||||
// after a clock over
|
||||
assertEquals( 1L, extractSequenceValue() );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 8L, generateValue() );
|
||||
// this should force an increment in the sequence value
|
||||
assertEquals( 2L, extractSequenceValue() );
|
||||
|
||||
((Session) sessionImpl).close();
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals(8L, generateValue());
|
||||
// this should force an increment in the sequence value
|
||||
assertEquals(2L, extractSequenceValue());
|
||||
} finally {
|
||||
( (Session) sessionImpl ).close();
|
||||
}
|
||||
}
|
||||
|
||||
private long extractSequenceValue() {
|
||||
|
@ -124,10 +125,12 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
private long generateValue() {
|
||||
Long generatedValue;
|
||||
Transaction transaction = ((Session) sessionImpl).beginTransaction();
|
||||
generatedValue = (Long) generator.generate( sessionImpl, null );
|
||||
transaction.commit();
|
||||
return generatedValue.longValue();
|
||||
Transaction transaction = ( (Session) sessionImpl ).beginTransaction();
|
||||
try {
|
||||
return (Long) generator.generate( sessionImpl, null );
|
||||
}
|
||||
finally {
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class SequenceValueExtractor {
|
|||
queryString = "select " + sequenceName + ".currval from dual";
|
||||
}
|
||||
else if ( dialect instanceof SQLServer2012Dialect ) {
|
||||
queryString = "SELECT CONVERT(varchar(200), Current_value) FROM SYS.Sequences WHERE name = '" + sequenceName + "'";
|
||||
queryString = "SELECT CONVERT(varchar(200), Current_value) FROM sys.sequences WHERE name = '" + sequenceName + "'";
|
||||
}
|
||||
else if ( dialect instanceof HSQLDialect ) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue