use of org.hibernate.TransientObjectException in project hibernate-orm by hibernate.
the class ReadOnlyProxyTest method testDetachedSetReadOnlyAfterEvictViaSession.
@Test
public void testDetachedSetReadOnlyAfterEvictViaSession() {
DataPoint dpOrig = createDataPoint(CacheMode.IGNORE);
Session s = openSession();
s.setCacheMode(CacheMode.IGNORE);
s.beginTransaction();
DataPoint dp = (DataPoint) s.load(DataPoint.class, new Long(dpOrig.getId()));
assertTrue(dp instanceof HibernateProxy);
assertFalse(Hibernate.isInitialized(dp));
checkReadOnly(s, dp, false);
assertTrue(s.contains(dp));
s.evict(dp);
assertFalse(s.contains(dp));
assertNull(((HibernateProxy) dp).getHibernateLazyInitializer().getSession());
try {
s.setReadOnly(dp, true);
fail("should have failed because proxy was detached");
} catch (TransientObjectException ex) {
// expected
assertFalse(((HibernateProxy) dp).getHibernateLazyInitializer().isReadOnlySettingAvailable());
} finally {
s.delete(dp);
s.getTransaction().commit();
s.close();
}
}
use of org.hibernate.TransientObjectException in project hibernate-orm by hibernate.
the class ReadOnlyProxyTest method testDetachedIsReadOnlyAfterEvictViaLazyInitializer.
@Test
public void testDetachedIsReadOnlyAfterEvictViaLazyInitializer() {
DataPoint dpOrig = createDataPoint(CacheMode.IGNORE);
Session s = openSession();
s.setCacheMode(CacheMode.IGNORE);
s.beginTransaction();
DataPoint dp = (DataPoint) s.load(DataPoint.class, new Long(dpOrig.getId()));
assertTrue(dp instanceof HibernateProxy);
assertFalse(Hibernate.isInitialized(dp));
checkReadOnly(s, dp, false);
s.evict(dp);
assertFalse(s.contains(dp));
assertNull(((HibernateProxy) dp).getHibernateLazyInitializer().getSession());
try {
((HibernateProxy) dp).getHibernateLazyInitializer().isReadOnly();
fail("should have failed because proxy was detached");
} catch (TransientObjectException ex) {
// expected
assertFalse(((HibernateProxy) dp).getHibernateLazyInitializer().isReadOnlySettingAvailable());
} finally {
s.delete(dp);
s.getTransaction().commit();
s.close();
}
}
Aggregations