}
@Test
public void testInsertGetUpdateGet() {
Session session = sf.openSession();
DummyEntity e = new DummyEntity(1L, "test", 0d, null);
Transaction tx = session.beginTransaction();
try {
session.save(e);
tx.commit();
} catch (Exception ex) {
ex.printStackTrace();
tx.rollback();
Assert.fail(ex.getMessage());
} finally {
session.close();
}
session = sf.openSession();
try {
e = (DummyEntity) session.get(DummyEntity.class, 1L);
assertEquals("test", e.getName());
assertNull(e.getDate());
} catch (Exception ex) {
ex.printStackTrace();
Assert.fail(ex.getMessage());
} finally {
session.close();
}
session = sf.openSession();
tx = session.beginTransaction();
try {
e = (DummyEntity) session.get(DummyEntity.class, 1L);
assertEquals("test", e.getName());
assertNull(e.getDate());
e.setName("dummy");
e.setDate(new Date());
session.update(e);
tx.commit();
} catch (Exception ex) {
ex.printStackTrace();
tx.rollback();
Assert.fail(ex.getMessage());
} finally {
session.close();
}
session = sf.openSession();
try {
e = (DummyEntity) session.get(DummyEntity.class, 1L);
assertEquals("dummy", e.getName());
Assert.assertNotNull(e.getDate());
} catch (Exception ex) {
ex.printStackTrace();
Assert.fail(ex.getMessage());
} finally {
session.close();