HHH-7237 - Inline natural-id synchronization doesn't consider reattached objects

This commit is contained in:
Guenther Demetz 2012-04-10 15:08:19 +03:00 committed by Steve Ebersole
parent d1a7495218
commit 572e78dce4
1 changed files with 46 additions and 1 deletions

View File

@ -28,6 +28,7 @@ import java.lang.reflect.Field;
import org.junit.Test;
import org.hibernate.HibernateException;
import org.hibernate.LockOptions;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
@ -98,6 +99,7 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s.beginTransaction();
try {
s.update( u );
assertNotNull(s.byNaturalId(User.class).using("name","Gavin").using("org", "hb").load());
s.getTransaction().commit();
}
catch( HibernateException expected ) {
@ -121,6 +123,50 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit();
s.close();
}
@Test
public void testReattachmentUnmodifiedNaturalIdCheck() throws Throwable {
Session s = openSession();
s.beginTransaction();
User u = new User( "gavin", "hb", "secret" );
s.persist( u );
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
try {
s.buildLockRequest(LockOptions.NONE).lock(u);
Field name = u.getClass().getDeclaredField("name");
name.setAccessible(true);
name.set(u, "Gavin");
assertNotNull(s.byNaturalId(User.class).using("name","Gavin").using("org", "hb").load());
s.getTransaction().commit();
}
catch( HibernateException expected ) {
s.getTransaction().rollback();
}
catch( Throwable t ) {
try {
s.getTransaction().rollback();
}
catch ( Throwable ignore ) {
}
throw t;
}
finally {
s.close();
}
s = openSession();
s.beginTransaction();
s.delete( u );
s.getTransaction().commit();
s.close();
}
@Test
public void testNonexistentNaturalIdCache() {
@ -427,4 +473,3 @@ public class MutableNaturalIdTest extends BaseCoreFunctionalTestCase {
s.close();
}
}