Search in sources :

Example 41 with Session

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

Example 42 with Session

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

Example 43 with Session

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

Example 44 with Session

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

Example 45 with Session

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

Aggregations

Session (org.hibernate.Session)3262 Test (org.junit.Test)2414 Transaction (org.hibernate.Transaction)1255 List (java.util.List)526 ArrayList (java.util.ArrayList)363 TestForIssue (org.hibernate.testing.TestForIssue)360 Query (org.hibernate.Query)224 Test (org.testng.annotations.Test)143 Iterator (java.util.Iterator)127 Date (java.util.Date)112 Map (java.util.Map)104 BigDecimal (java.math.BigDecimal)97 Criteria (org.hibernate.Criteria)92 HashSet (java.util.HashSet)90 HibernateException (org.hibernate.HibernateException)82 HashMap (java.util.HashMap)70 SQLException (java.sql.SQLException)66 SkipForDialect (org.hibernate.testing.SkipForDialect)66 Connection (java.sql.Connection)65 Serializable (java.io.Serializable)62