diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java index 9fbdfa7187..877461835c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/EntityTest.java @@ -190,6 +190,7 @@ public class EntityTest extends BaseCoreFunctionalTestCase { int id = 5; Session s; Transaction tx; + s = openSession(); tx = s.beginTransaction(); Sky sky = new Sky(); @@ -197,6 +198,9 @@ public class EntityTest extends BaseCoreFunctionalTestCase { sky.color = "green"; sky.day = "monday"; sky.month = "March"; + s.persist( sky ); + tx.commit(); + s.close(); Sky otherSky = new Sky(); otherSky.id = new Long( id++ ); @@ -210,17 +214,25 @@ public class EntityTest extends BaseCoreFunctionalTestCase { sameSky.day = "monday"; sameSky.month = "March"; - s.save( sky ); - s.flush(); - - s.save( otherSky ); - tx.commit(); - s.close(); + s = openSession(); + tx = s.beginTransaction(); + try { + s.persist( otherSky ); + tx.commit(); + fail( "unique constraints not respected" ); + } + catch (HibernateException e) { + //success + } + finally { + if ( tx != null ) tx.rollback(); + s.close(); + } s = openSession(); tx = s.beginTransaction(); try { - s.save( sameSky ); + s.persist( sameSky ); tx.commit(); fail( "unique constraints not respected" ); }