use of org.hibernate.TransientObjectException in project hibernate-orm by hibernate.
the class CascadeTest method testOneToOnePropertyRefGeneratedIds.
public void testOneToOnePropertyRefGeneratedIds() {
try {
Session s = openSession();
s.beginTransaction();
Child c2 = new Child("c2");
ChildInfo info = new ChildInfo("blah blah blah");
c2.setInfo(info);
info.setOwner(c2);
s.persist(c2);
try {
s.getTransaction().commit();
fail("expecting TransientObjectException on flush");
} catch (TransientObjectException e) {
// expected result
log.trace("handled expected exception : " + e);
s.getTransaction().rollback();
} finally {
s.close();
}
} finally {
cleanupData();
}
}
use of org.hibernate.TransientObjectException in project hibernate-orm by hibernate.
the class ReadOnlyProxyTest method testIsReadOnlyAfterSessionClosedViaLazyInitializer.
@Test
public void testIsReadOnlyAfterSessionClosedViaLazyInitializer() {
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.getTransaction().commit();
assertTrue(s.contains(dp));
s.close();
assertNull(((HibernateProxy) dp).getHibernateLazyInitializer().getSession());
try {
((HibernateProxy) dp).getHibernateLazyInitializer().isReadOnly();
fail("should have failed because session was detached");
} catch (TransientObjectException ex) {
// expected
assertFalse(((HibernateProxy) dp).getHibernateLazyInitializer().isReadOnlySettingAvailable());
} finally {
s = openSession();
s.beginTransaction();
s.delete(dp);
s.getTransaction().commit();
s.close();
}
}
use of org.hibernate.TransientObjectException in project hibernate-orm by hibernate.
the class ReadOnlyProxyTest method testDetachedSetReadOnlyAfterEvictViaLazyInitializer.
@Test
public void testDetachedSetReadOnlyAfterEvictViaLazyInitializer() {
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().setReadOnly(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 testDetachedIsReadOnlyAfterEvictViaSession.
@Test
public void testDetachedIsReadOnlyAfterEvictViaSession() {
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.isReadOnly(dp);
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 testSetReadOnlyAfterSessionClosedViaLazyInitializer.
@Test
public void testSetReadOnlyAfterSessionClosedViaLazyInitializer() {
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.getTransaction().commit();
assertTrue(s.contains(dp));
s.close();
assertNull(((HibernateProxy) dp).getHibernateLazyInitializer().getSession());
try {
((HibernateProxy) dp).getHibernateLazyInitializer().setReadOnly(true);
fail("should have failed because session was detached");
} catch (TransientObjectException ex) {
// expected
assertFalse(((HibernateProxy) dp).getHibernateLazyInitializer().isReadOnlySettingAvailable());
} finally {
s = openSession();
s.beginTransaction();
s.delete(dp);
s.getTransaction().commit();
s.close();
}
}
Aggregations