use of org.hibernate.Session in project hibernate-orm by hibernate.
the class LocalDateTest method testLocalDate.
@Test
public void testLocalDate() {
final Session s = openSession();
try {
final LocalDateEvent localDateEvent = s.get(LocalDateEvent.class, 1L);
assertThat(localDateEvent.getStartDate(), is(expectedLocalDate));
} finally {
s.close();
}
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class LocalDateTest method setUp.
@Before
public void setUp() {
final Session s = openSession();
s.getTransaction().begin();
try {
s.save(new LocalDateEvent(1L, expectedLocalDate));
s.getTransaction().commit();
} catch (Exception e) {
if (s.getTransaction() != null && s.getTransaction().getStatus() == TransactionStatus.ACTIVE) {
s.getTransaction().rollback();
}
fail(e.getMessage());
} finally {
s.close();
}
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class ResultCheckStyleTest method testUpdateFailureWithExceptionChecking.
@Test
public void testUpdateFailureWithExceptionChecking() {
Session s = openSession();
s.beginTransaction();
ExceptionCheckingEntity e = new ExceptionCheckingEntity();
e.setId(Long.valueOf(1));
e.setName("dummy");
s.update(e);
try {
s.flush();
fail("expection flush failure!");
} catch (Exception ex) {
// these should specifically be JDBCExceptions...
}
s.clear();
s.getTransaction().rollback();
s.close();
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class CustomSQLTestSupport method testTextProperty.
@Test
public void testTextProperty() {
Session s = openSession();
Transaction t = s.beginTransaction();
String description = buildLongString(15000, 'a');
TextHolder holder = new TextHolder(description);
s.save(holder);
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
holder = (TextHolder) s.get(TextHolder.class, holder.getId());
assertEquals(description, holder.getDescription());
description = buildLongString(15000, 'b');
holder.setDescription(description);
s.save(holder);
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
holder = (TextHolder) s.get(TextHolder.class, holder.getId());
assertEquals(description, holder.getDescription());
s.delete(holder);
t.commit();
s.close();
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class CustomStoredProcTestSupport method testEntityStoredProcedure.
@Test
public void testEntityStoredProcedure() throws HibernateException, SQLException {
Session s = openSession();
Transaction t = s.beginTransaction();
Organization ifa = new Organization("IFA");
Organization jboss = new Organization("JBoss");
Person gavin = new Person("Gavin");
Employment emp = new Employment(gavin, jboss, "AU");
s.persist(ifa);
s.persist(jboss);
s.persist(gavin);
s.persist(emp);
Query namedQuery = s.getNamedQuery("selectAllEmployments");
List list = namedQuery.list();
assertTrue(list.get(0) instanceof Employment);
s.delete(emp);
s.delete(ifa);
s.delete(jboss);
s.delete(gavin);
t.commit();
s.close();
}
Aggregations