HHH-1645 : Refresh with LockMode on an unitialized proxy does not work
This commit is contained in:
parent
4cbbdb65fd
commit
aee2312475
|
@ -30,6 +30,7 @@ import org.hibernate.FlushMode;
|
|||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.LazyInitializationException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.ObjectNotFoundException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
|
@ -41,6 +42,7 @@ import org.hibernate.proxy.HibernateProxy;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -430,5 +432,85 @@ public class ProxyTest extends BaseCoreFunctionalTestCase {
|
|||
t.commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshLockInitializedProxy() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
DataPoint dp = newPersistentDataPoint( s );
|
||||
|
||||
dp = ( DataPoint ) s.load( DataPoint.class, new Long( dp.getId() ) );
|
||||
dp.getX();
|
||||
assertTrue( Hibernate.isInitialized( dp ) );
|
||||
|
||||
s.refresh( dp, LockOptions.UPGRADE );
|
||||
assertSame( LockOptions.UPGRADE.getLockMode(), s.getCurrentLockMode( dp ) );
|
||||
|
||||
s.delete( dp );
|
||||
t.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@FailureExpected( jiraKey = "HHH-1645", message = "Session.refresh with LockOptions does not work on uninitialized proxies" )
|
||||
public void testRefreshLockUninitializedProxy() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
DataPoint dp = newPersistentDataPoint( s );
|
||||
|
||||
dp = ( DataPoint ) s.load( DataPoint.class, new Long( dp.getId() ) );
|
||||
assertFalse( Hibernate.isInitialized( dp ) );
|
||||
|
||||
s.refresh( dp, LockOptions.UPGRADE );
|
||||
assertSame( LockOptions.UPGRADE.getLockMode(), s.getCurrentLockMode( dp ) );
|
||||
|
||||
s.delete( dp );
|
||||
t.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
private static DataPoint newPersistentDataPoint(Session s) {
|
||||
DataPoint dp = new DataPoint();
|
||||
dp.setDescription( "a data point" );
|
||||
dp.setX( new BigDecimal( 1.0 ) );
|
||||
dp.setY( new BigDecimal( 2.0 ) );
|
||||
s.persist( dp );
|
||||
s.flush();
|
||||
s.clear();
|
||||
return dp;
|
||||
}
|
||||
|
||||
@Test
|
||||
@FailureExpected( jiraKey = "HHH-1645", message = "Session.refresh with LockOptions does not work on uninitialized proxies" )
|
||||
public void testRefreshLockUninitializedProxyThenRead() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
DataPoint dp = newPersistentDataPoint( s );
|
||||
|
||||
dp = ( DataPoint ) s.load( DataPoint.class, new Long( dp.getId() ) );
|
||||
assertFalse( Hibernate.isInitialized( dp ) );
|
||||
s.refresh( dp, LockOptions.UPGRADE );
|
||||
dp.getX();
|
||||
assertSame( LockOptions.UPGRADE.getLockMode(), s.getCurrentLockMode( dp ) );
|
||||
|
||||
s.delete( dp );
|
||||
t.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLockUninitializedProxy() {
|
||||
Session s = openSession();
|
||||
Transaction t = s.beginTransaction();
|
||||
DataPoint dp = newPersistentDataPoint( s );
|
||||
|
||||
dp = ( DataPoint) s.load( DataPoint.class, new Long( dp.getId() ) );
|
||||
assertFalse( Hibernate.isInitialized( dp ) );
|
||||
s.buildLockRequest( LockOptions.UPGRADE ).lock( dp );
|
||||
assertSame( LockOptions.UPGRADE.getLockMode(), s.getCurrentLockMode( dp ) );
|
||||
|
||||
s.delete( dp );
|
||||
t.commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue