HHH-8814 : test case

This commit is contained in:
Benoit GUERIN 2014-02-11 11:01:11 +01:00 committed by Brett Meyer
parent 2d8e5b4c25
commit 949df8bd00
3 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,14 @@
<?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" />
</id>
</class>
</hibernate-mapping>

View File

@ -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;
}
}

View File

@ -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();
}
}