HHH-9169 : SQLServer2012Dialect creates sequences starting from Long.MIN_VALUE

This commit is contained in:
Gail Badner 2014-05-13 22:42:28 -07:00
parent b945cc2709
commit 642012aac0
4 changed files with 65 additions and 1 deletions

View File

@ -7,7 +7,7 @@
<class name="Person">
<id name="id" type="long">
<generator class="sequence"/>
<generator class="enhanced-sequence"/>
</id>
<property name="name" type="string"/>
<property name="weight" type="integer"/>

View File

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.id">
<class name="Person">
<id name="id" column="id">
<generator class="sequence">
<param name="parameters">start with 10</param>
</generator>
</id>
</class>
</hibernate-mapping>

View File

@ -0,0 +1,42 @@
package org.hibernate.test.id;
import static org.junit.Assert.assertTrue;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.dialect.SQLServer2012Dialect;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
public class SQLServer2012SequenceGeneratorTest extends BaseCoreFunctionalTestCase {
@Override
public String[] getMappings() {
return new String[] { "id/SQLServer2012Person.hbm.xml" };
}
/**
* SQL server requires that sequence be initialized to something other than the minimum value for the type
* (e.g., Long.MIN_VALUE). For generator = "sequence", the initial value must be provided as a parameter.
* For this test, the sequence is initialized to 10.
*/
@Test
@TestForIssue(jiraKey = "HHH-8814")
@RequiresDialect(value=SQLServer2012Dialect.class)
public void testStartOfSequence() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
final Person person = new Person();
s.persist(person);
tx.commit();
s.close();
assertTrue(person.getId() == 10);
}
}

View File

@ -4,8 +4,10 @@ import static org.junit.Assert.assertTrue;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.dialect.SQLServer2012Dialect;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
@ -23,6 +25,10 @@ public class SequenceGeneratorTest extends BaseCoreFunctionalTestCase {
@Test
@TestForIssue(jiraKey = "HHH-8814")
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
@SkipForDialect(
value= SQLServer2012Dialect.class,
comment="SQLServer2012Dialect initializes sequence to minimum value (e.g., Long.MIN_VALUE; Hibernate assumes it is uninitialized."
)
public void testStartOfSequence() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();