use of org.hibernate.proxy.HibernateProxy in project hibernate-orm by hibernate.
the class ReadOnlyProxyTest method testModifyToReadOnlyToModifiableIsUpdated.
@Test
@FailureExpected(jiraKey = "HHH-4642")
public void testModifyToReadOnlyToModifiableIsUpdated() {
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);
dp.setDescription("changed");
assertTrue(Hibernate.isInitialized(dp));
assertEquals("changed", dp.getDescription());
s.setReadOnly(dp, true);
checkReadOnly(s, dp, true);
s.setReadOnly(dp, false);
checkReadOnly(s, dp, false);
assertEquals("changed", dp.getDescription());
s.flush();
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
dp = (DataPoint) s.get(DataPoint.class, dpOrig.getId());
assertEquals(dpOrig.getId(), dp.getId());
assertEquals(dpOrig.getDescription(), dp.getDescription());
assertEquals(dpOrig.getX(), dp.getX());
assertEquals(dpOrig.getY(), dp.getY());
try {
assertEquals("changed", dp.getDescription());
// should fail due to HHH-4642
} finally {
s.getTransaction().rollback();
s.close();
s = openSession();
s.beginTransaction();
s.delete(dp);
s.getTransaction().commit();
s.close();
}
}
use of org.hibernate.proxy.HibernateProxy in project hibernate-orm by hibernate.
the class ReadOnlyProxyTest method testReadOnlyViaSessionBeforeInit.
@Test
public void testReadOnlyViaSessionBeforeInit() {
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);
s.setReadOnly(dp, true);
dp.setDescription("changed");
assertTrue(Hibernate.isInitialized(dp));
assertEquals("changed", dp.getDescription());
checkReadOnly(s, dp, true);
s.flush();
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
dp = (DataPoint) s.get(DataPoint.class, dpOrig.getId());
assertEquals(dpOrig.getId(), dp.getId());
assertEquals(dpOrig.getDescription(), dp.getDescription());
assertEquals(dpOrig.getX(), dp.getX());
assertEquals(dpOrig.getY(), dp.getY());
s.delete(dp);
s.getTransaction().commit();
s.close();
}
use of org.hibernate.proxy.HibernateProxy in project hibernate-orm by hibernate.
the class ReadOnlyProxyTest method testReadOnlyViaSessionBeforeInitByModifiableQuery.
@Test
public void testReadOnlyViaSessionBeforeInitByModifiableQuery() {
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.setReadOnly(dp, true);
assertFalse(Hibernate.isInitialized(dp));
checkReadOnly(s, dp, true);
assertFalse(Hibernate.isInitialized(dp));
DataPoint dpFromQuery = (DataPoint) s.createQuery("from DataPoint where id=" + dpOrig.getId()).setReadOnly(false).uniqueResult();
assertTrue(Hibernate.isInitialized(dpFromQuery));
assertSame(dp, dpFromQuery);
checkReadOnly(s, dp, true);
dp.setDescription("changed");
assertEquals("changed", dp.getDescription());
s.flush();
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
dp = (DataPoint) s.get(DataPoint.class, dpOrig.getId());
assertEquals(dpOrig.getId(), dp.getId());
assertEquals(dpOrig.getDescription(), dp.getDescription());
assertEquals(dpOrig.getX(), dp.getX());
assertEquals(dpOrig.getY(), dp.getY());
s.delete(dp);
s.getTransaction().commit();
s.close();
}
use of org.hibernate.proxy.HibernateProxy in project hibernate-orm by hibernate.
the class ReadOnlyProxyTest method testSetClosedSessionInLazyInitializer.
@Test
public void testSetClosedSessionInLazyInitializer() {
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());
assertTrue(((SessionImplementor) s).isClosed());
try {
((HibernateProxy) dp).getHibernateLazyInitializer().setSession((SessionImplementor) s);
fail("should have failed because session was closed");
} catch (IllegalStateException ex) {
// expected
assertFalse(((HibernateProxy) dp).getHibernateLazyInitializer().isReadOnlySettingAvailable());
} finally {
s = openSession();
s.beginTransaction();
s.delete(dp);
s.getTransaction().commit();
s.close();
}
}
use of org.hibernate.proxy.HibernateProxy in project hibernate-orm by hibernate.
the class ReadOnlyProxyTest method testReadOnlyModifiedUpdate.
@Test
public void testReadOnlyModifiedUpdate() {
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);
checkReadOnly(s, dp, false);
s.setReadOnly(dp, true);
checkReadOnly(s, dp, true);
assertFalse(Hibernate.isInitialized(dp));
dp.setDescription("changed");
assertTrue(Hibernate.isInitialized(dp));
assertEquals("changed", dp.getDescription());
checkReadOnly(s, dp, true);
s.update(dp);
s.flush();
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
dp = (DataPoint) s.get(DataPoint.class, dpOrig.getId());
assertEquals(dpOrig.getId(), dp.getId());
assertEquals(dpOrig.getDescription(), dp.getDescription());
assertEquals(dpOrig.getX(), dp.getX());
assertEquals(dpOrig.getY(), dp.getY());
s.delete(dp);
s.getTransaction().commit();
s.close();
}
Aggregations