Search in sources :

Example 16 with Session

use of org.hibernate.Session in project hibernate-orm by hibernate.

the class BaseCoreFunctionalTestCase method readCommittedIsolationMaintained.

protected boolean readCommittedIsolationMaintained(String scenario) {
    int isolation = java.sql.Connection.TRANSACTION_READ_UNCOMMITTED;
    Session testSession = null;
    try {
        testSession = openSession();
        isolation = testSession.doReturningWork(new AbstractReturningWork<Integer>() {

            @Override
            public Integer execute(Connection connection) throws SQLException {
                return connection.getTransactionIsolation();
            }
        });
    } catch (Throwable ignore) {
    } finally {
        if (testSession != null) {
            try {
                testSession.close();
            } catch (Throwable ignore) {
            }
        }
    }
    if (isolation < java.sql.Connection.TRANSACTION_READ_COMMITTED) {
        SkipLog.reportSkip("environment does not support at least read committed isolation", scenario);
        return false;
    } else {
        return true;
    }
}
Also used : AbstractReturningWork(org.hibernate.jdbc.AbstractReturningWork) Connection(java.sql.Connection) Session(org.hibernate.Session)

Example 17 with Session

use of org.hibernate.Session in project hibernate-orm by hibernate.

the class InsertedDataTest method testInsertWithClear.

@Test
public void testInsertWithClear() {
    sessionFactory().getCache().evictEntityRegions();
    sessionFactory().getStatistics().clear();
    Session s = openSession();
    s.beginTransaction();
    CacheableItem item = new CacheableItem("data");
    s.save(item);
    s.flush();
    s.clear();
    s.getTransaction().commit();
    s.close();
    Map cacheMap = sessionFactory().getStatistics().getSecondLevelCacheStatistics("item").getEntries();
    assertEquals(1, cacheMap.size());
    s = openSession();
    s.beginTransaction();
    s.createQuery("delete CacheableItem").executeUpdate();
    s.getTransaction().commit();
    s.close();
}
Also used : Map(java.util.Map) Session(org.hibernate.Session) Test(org.junit.Test)

Example 18 with Session

use of org.hibernate.Session in project hibernate-orm by hibernate.

the class InsertedDataTest method testInsertWithRefresh.

@Test
public void testInsertWithRefresh() {
    sessionFactory().getCache().evictEntityRegions();
    sessionFactory().getStatistics().clear();
    Session s = openSession();
    s.beginTransaction();
    CacheableItem item = new CacheableItem("data");
    s.save(item);
    s.flush();
    s.refresh(item);
    s.getTransaction().commit();
    s.close();
    Map cacheMap = sessionFactory().getStatistics().getSecondLevelCacheStatistics("item").getEntries();
    assertEquals(1, cacheMap.size());
    s = openSession();
    s.beginTransaction();
    s.createQuery("delete CacheableItem").executeUpdate();
    s.getTransaction().commit();
    s.close();
}
Also used : Map(java.util.Map) Session(org.hibernate.Session) Test(org.junit.Test)

Example 19 with Session

use of org.hibernate.Session in project hibernate-orm by hibernate.

the class InsertedDataTest method testInsertWithClearThenRollback.

@Test
public void testInsertWithClearThenRollback() {
    sessionFactory().getCache().evictEntityRegions();
    sessionFactory().getStatistics().clear();
    Session s = openSession();
    s.beginTransaction();
    CacheableItem item = new CacheableItem("data");
    s.save(item);
    s.flush();
    s.clear();
    item = (CacheableItem) s.get(CacheableItem.class, item.getId());
    s.getTransaction().rollback();
    s.close();
    Map cacheMap = sessionFactory().getStatistics().getSecondLevelCacheStatistics("item").getEntries();
    assertEquals(0, cacheMap.size());
    s = openSession();
    s.beginTransaction();
    item = (CacheableItem) s.get(CacheableItem.class, item.getId());
    s.getTransaction().commit();
    s.close();
    assertNull("it should be null", item);
}
Also used : Map(java.util.Map) Session(org.hibernate.Session) Test(org.junit.Test)

Example 20 with Session

use of org.hibernate.Session in project hibernate-orm by hibernate.

the class InsertedDataTest method testInsertThenUpdate.

@Test
public void testInsertThenUpdate() {
    sessionFactory().getCache().evictEntityRegions();
    sessionFactory().getStatistics().clear();
    Session s = openSession();
    s.beginTransaction();
    CacheableItem item = new CacheableItem("data");
    s.save(item);
    s.flush();
    item.setName("new data");
    s.getTransaction().commit();
    s.close();
    Map cacheMap = sessionFactory().getStatistics().getSecondLevelCacheStatistics("item").getEntries();
    assertEquals(1, cacheMap.size());
    s = openSession();
    s.beginTransaction();
    s.createQuery("delete CacheableItem").executeUpdate();
    s.getTransaction().commit();
    s.close();
}
Also used : Map(java.util.Map) 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