From 949df8bd00f32193a0529a1568bcfbc040f5fd43 Mon Sep 17 00:00:00 2001 From: Benoit GUERIN Date: Tue, 11 Feb 2014 11:01:11 +0100 Subject: [PATCH] HHH-8814 : test case --- .../java/org/hibernate/test/id/Person.hbm.xml | 14 +++++++ .../java/org/hibernate/test/id/Person.java | 19 +++++++++ .../test/id/SequenceGeneratorTest.java | 40 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/id/Person.hbm.xml create mode 100644 hibernate-core/src/test/java/org/hibernate/test/id/Person.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/id/SequenceGeneratorTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/id/Person.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/id/Person.hbm.xml new file mode 100644 index 0000000000..4e32f5a5dd --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/id/Person.hbm.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/id/Person.java b/hibernate-core/src/test/java/org/hibernate/test/id/Person.java new file mode 100644 index 0000000000..f603f9ed8c --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/id/Person.java @@ -0,0 +1,19 @@ +package org.hibernate.test.id; + + +public class Person { + + private Long id; + + public Person() { + } + + public Long getId() { + return id; + } + + public void setId(final Long id) { + this.id = id; + } + +} 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 new file mode 100644 index 0000000000..532276ee56 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/id/SequenceGeneratorTest.java @@ -0,0 +1,40 @@ +package org.hibernate.test.id; + +import static org.junit.Assert.assertEquals; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +public class SequenceGeneratorTest extends BaseCoreFunctionalTestCase { + + @Override + public String[] getMappings() { + return new String[] { "id/Person.hbm.xml" }; + } + + @Test + public void testDistinctId() throws Exception { + Session s = openSession(); + Transaction tx = s.beginTransaction(); + final int testLength = 8; + final Person[] persons = new Person[testLength]; + for (int i = 0; i < testLength; i++) { + persons[i] = new Person(); + s.persist(persons[i]); + } + tx.commit(); + s.close(); + for (int i = 0; i < testLength; i++) { + assertEquals(i + 1, persons[i].getId().intValue()); + } + + s = openSession(); + tx = s.beginTransaction(); + s.createQuery("delete from Person").executeUpdate(); + tx.commit(); + s.close(); + } + +}