added test for stale merging

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@14180 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2007-11-02 16:11:05 +00:00
parent 0705b2ca78
commit d3ddcc4c55
1 changed files with 34 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.NonUniqueObjectException;
import org.hibernate.StaleObjectStateException;
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
import org.hibernate.criterion.Projections;
@ -27,6 +28,39 @@ public class MergeTest extends AbstractOperationTestCase {
return new FunctionalTestClassTestSuite( MergeTest.class );
}
public void testMergeStaleVersionFails() throws Exception {
Session s = openSession();
s.beginTransaction();
VersionedEntity entity = new VersionedEntity( "entity", "entity" );
s.persist( entity );
s.getTransaction().commit();
s.close();
// make the detached 'entity' reference stale...
s = openSession();
s.beginTransaction();
VersionedEntity entity2 = ( VersionedEntity ) s.get( VersionedEntity.class, entity.getId() );
entity2.setName( "entity-name" );
s.getTransaction().commit();
s.close();
// now try to reattch it
s = openSession();
s.beginTransaction();
try {
s.merge( entity );
s.getTransaction().commit();
fail( "was expecting staleness error" );
}
catch ( StaleObjectStateException expected ) {
// expected outcome...
}
finally {
s.getTransaction().rollback();
s.close();
}
}
public void testMergeBidiPrimayKeyOneToOne() throws Exception {
Session s = openSession();
s.beginTransaction();