Search in sources :

Example 56 with Session

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();
    }
}
Also used : Session(org.hibernate.Session) Test(org.junit.Test)

Example 57 with Session

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();
    }
}
Also used : Session(org.hibernate.Session) Before(org.junit.Before)

Example 58 with Session

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();
}
Also used : Session(org.hibernate.Session) Test(org.junit.Test)

Example 59 with Session

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();
}
Also used : Transaction(org.hibernate.Transaction) TextHolder(org.hibernate.test.sql.hand.TextHolder) Session(org.hibernate.Session) Test(org.junit.Test)

Example 60 with Session

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();
}
Also used : Organization(org.hibernate.test.sql.hand.Organization) Transaction(org.hibernate.Transaction) Query(org.hibernate.Query) Employment(org.hibernate.test.sql.hand.Employment) List(java.util.List) Person(org.hibernate.test.sql.hand.Person) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

Session (org.hibernate.Session)4457 Test (org.junit.Test)2517 Transaction (org.hibernate.Transaction)1327 List (java.util.List)576 ArrayList (java.util.ArrayList)475 Test (org.testng.annotations.Test)411 TestForIssue (org.hibernate.testing.TestForIssue)389 Query (org.hibernate.Query)345 HibernateException (org.hibernate.HibernateException)299 DAOException (com.tomasio.projects.trainning.exception.DAOException)186 Criteria (org.hibernate.Criteria)174 Date (java.util.Date)134 Iterator (java.util.Iterator)127 SkipForDialect (org.hibernate.testing.SkipForDialect)114 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)113 SQLException (java.sql.SQLException)108 Map (java.util.Map)105 SessionFactory (org.hibernate.SessionFactory)105 GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)104 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)104