@Test
public void testUpdateAndRefresh() {
Session s = openSession();
s.beginTransaction();
CacheableItem item = new CacheableItem( "item" );
s.save( item );
s.getTransaction().commit();
s.close();
Session s1 = openSession();
s1.beginTransaction();
CacheableItem item1 = s1.get( CacheableItem.class, item.getId() ); item1.setName( "some name" );
s1.flush();
s1.clear(); s1.refresh( item1 );
item1 = s1.get( CacheableItem.class, item.getId() );
assertEquals( "some name", item1.getName() );
Session s2 = sessionFactory().openSession();
try {
s2.beginTransaction();
CacheableItem item2 = s2.get( CacheableItem.class, item.getId() );
assertEquals( "item", item2.getName() );
} catch (PessimisticLockException expected) {
} catch (Exception e) {
throw e;
} finally {
s2.getTransaction().rollback();
s2.close();
}
s1.getTransaction().rollback();
s1.close();
}