Каталог статей
Меню сайта


Форма входа


Категории раздела
WebLogic administration and programming [7]
JSF and Primefaces [1]
Java general programming [12]
Other Java problems [11]
JPA and Hibernate [2]
Spring [2]
Spring


Поиск


Друзья сайта
  • Официальный блог
  • Сообщество uCoz
  • FAQ по системе
  • Инструкции для uCoz


  • Статистика

    Онлайн всего: 1
    Гостей: 1
    Пользователей: 0


    Приветствую Вас, Гость · RSS 09.05.2024, 09:46
    Главная » Статьи » Java » JPA and Hibernate

    How to check isolation level in hibernate session

    import java.sql.Connection;
    import java.sql.SQLException;
    import javax.persistence.EntityManager;
    import javax.persistence.FlushModeType;
    import javax.persistence.LockModeType;
    import javax.persistence.Query;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.cfg.Configuration;
    import org.hibernate.cfg.Environment;
    import org.hibernate.jdbc.Work;
    import static org.junit.Assert.assertTrue;
    import org.junit.Test;

     

    public class TestIsolation {

        @Test
        public void testIsolationLevel() {
            Connection cc = null;
            Session session = null;
            Transaction txn = null;
            EntityManager entityManager = entityManagerFactory.createEntityManager();
            try {
                session = entityManager.unwrap(Session.class);
                txn = session.beginTransaction();
                session.doWork(new Work() {
                    @Override
                    public void execute(Connection connection) throws SQLException {
                        Connection c = connection;
                        c.toString();
                        System.out.println("Transaction isolation level is " + Environment.isolationLevelToString(connection.getTransactionIsolation() ) );
                    }
                });
                txn.commit();
            } catch (RuntimeException e) {
                if ( txn != null && txn.isActive() ) txn.rollback();
                throw e;
            } finally {
                if (session != null) {
                    session.close();
                }
            }        
        }


    }

    Категория: JPA and Hibernate | Добавил: basil (15.07.2016)
    Просмотров: 444 | Рейтинг: 0.0/0
    Всего комментариев: 0
    Имя *:
    Email *:
    Код *:
    Бесплатный конструктор сайтов - uCoz