diff --git a/hibernate-core/src/test/java/org/hibernate/test/criteria/Person.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/criteria/Person.hbm.xml index dec080e975..9ea6a3b370 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/criteria/Person.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/test/criteria/Person.hbm.xml @@ -7,7 +7,7 @@ - + diff --git a/hibernate-core/src/test/java/org/hibernate/test/id/SQLServer2012Person.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/id/SQLServer2012Person.hbm.xml new file mode 100644 index 0000000000..b0663a6b49 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/id/SQLServer2012Person.hbm.xml @@ -0,0 +1,16 @@ + + + + + + + + + start with 10 + + + + + \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/id/SQLServer2012SequenceGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/test/id/SQLServer2012SequenceGeneratorTest.java new file mode 100644 index 0000000000..25cf69c0ee --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/id/SQLServer2012SequenceGeneratorTest.java @@ -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); + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/id/SequenceGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/test/id/SequenceGeneratorTest.java index c43c362609..5a50b71e00 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/id/SequenceGeneratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/id/SequenceGeneratorTest.java @@ -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();