use of org.hibernate.Session in project hibernate-orm by hibernate.
the class ResultCheckStyleTest method testInsertionFailureWithParamChecking.
@Test
public void testInsertionFailureWithParamChecking() {
Session s = openSession();
s.beginTransaction();
ParamCheckingEntity e = new ParamCheckingEntity();
e.setName("dummy");
s.save(e);
try {
s.flush();
fail("expection flush failure!");
} catch (Exception ex) {
// these should specifically be HibernateExceptions...
}
s.clear();
s.getTransaction().rollback();
s.close();
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class LocalDateTimeVersionTest method testInstantUsageAsVersion.
@Test
public void testInstantUsageAsVersion() {
Session session = openSession();
session.getTransaction().begin();
TheEntity e = new TheEntity(1);
session.save(e);
session.getTransaction().commit();
session.close();
session = openSession();
session.getTransaction().begin();
e = session.byId(TheEntity.class).load(1);
assertThat(e.getTs(), notNullValue());
session.getTransaction().commit();
session.close();
session = openSession();
session.getTransaction().begin();
e = session.byId(TheEntity.class).load(1);
session.delete(e);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class OffsetDateTimeVersionTest method testInstantUsageAsVersion.
@Test
public void testInstantUsageAsVersion() {
Session session = openSession();
session.getTransaction().begin();
TheEntity e = new TheEntity(1);
session.save(e);
session.getTransaction().commit();
session.close();
session = openSession();
session.getTransaction().begin();
e = session.byId(TheEntity.class).load(1);
assertThat(e.getTs(), notNullValue());
session.getTransaction().commit();
session.close();
session = openSession();
session.getTransaction().begin();
e = session.byId(TheEntity.class).load(1);
session.delete(e);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class VersionTest method testVersionShortCircuitFlush.
@Test
public void testVersionShortCircuitFlush() {
Session s = openSession();
Transaction t = s.beginTransaction();
Person gavin = new Person("Gavin");
new Thing("Passport", gavin);
s.persist(gavin);
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
Thing passp = (Thing) s.get(Thing.class, "Passport");
passp.setLongDescription("blah blah blah");
s.createQuery("from Person").list();
s.createQuery("from Person").list();
s.createQuery("from Person").list();
t.commit();
s.close();
assertEquals(passp.getVersion(), 1);
s = openSession();
t = s.beginTransaction();
s.createQuery("delete from Thing").executeUpdate();
s.createQuery("delete from Person").executeUpdate();
t.commit();
s.close();
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class ZonedDateTimeVersionTest method testInstantUsageAsVersion.
@Test
public void testInstantUsageAsVersion() {
Session session = openSession();
session.getTransaction().begin();
TheEntity e = new TheEntity(1);
session.save(e);
session.getTransaction().commit();
session.close();
session = openSession();
session.getTransaction().begin();
e = session.byId(TheEntity.class).load(1);
assertThat(e.getTs(), notNullValue());
session.getTransaction().commit();
session.close();
session = openSession();
session.getTransaction().begin();
e = session.byId(TheEntity.class).load(1);
session.delete(e);
session.getTransaction().commit();
session.close();
}
Aggregations