HHH-11456 - SequenceHiLoGeneratorTest fails due to wrong select string on SQL Server
This commit is contained in:
parent
f82dd465b1
commit
e46956b0f1
|
@ -8,7 +8,6 @@ package org.hibernate.id;
|
|||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
|
@ -88,34 +87,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() );
|
||||
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(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() );
|
||||
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(1L, extractSequenceValue());
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 8L, generateValue() );
|
||||
assertEquals(8L, generateValue());
|
||||
// this should force an increment in the sequence value
|
||||
assertEquals( 2L, extractSequenceValue() );
|
||||
|
||||
((Session) sessionImpl).close();
|
||||
assertEquals(2L, extractSequenceValue());
|
||||
} finally {
|
||||
sessionImpl.close();
|
||||
}
|
||||
}
|
||||
|
||||
private long extractSequenceValue() {
|
||||
|
@ -123,10 +123,12 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase {
|
|||
}
|
||||
|
||||
private long generateValue() {
|
||||
Long generatedValue;
|
||||
Transaction transaction = ((Session) sessionImpl).beginTransaction();
|
||||
generatedValue = (Long) generator.generate( sessionImpl, null );
|
||||
Transaction transaction = sessionImpl.beginTransaction();
|
||||
try {
|
||||
return (Long) generator.generate( sessionImpl, null );
|
||||
}
|
||||
finally {
|
||||
transaction.commit();
|
||||
return generatedValue.longValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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