HHH-8814 : test case
This commit is contained in:
parent
37c4e172af
commit
6660bd8d37
|
@ -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>
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue