简体   繁体   English

如何找出用于休眠中特定查询的事务隔离级别?

[英]How to find out the transaction isolation level used for the particular query in hibernate?

I am using Spring MVC and hibernate.我正在使用 Spring MVC 和休眠。 My underlying database is Sybase ASA.我的底层数据库是 Sybase ASA。 Inside my DAO I want to find out what is the transaction level used for the query在我的 DAO 中,我想了解用于查询的事务级别是什么

This is what my DAO has.这就是我的 DAO 所拥有的。

Session session = getSession();
String SQL_QUERY = "select ..... ";
Query query = session.createSQLQuery(SQL_QUERY);
query.executeUpdate(); 

I referred to this link but this seems to be outdated so doesn't work What is default isolation level hibernate uses if not explicitely set?我提到了这个链接,但这似乎已经过时,所以不起作用如果没有明确设置,休眠使用的默认隔离级别是什么?

I would say that question is raised incorrectly: a query itself doesn't have any isolation level.我会说这个问题是错误地提出的:查询本身没有任何隔离级别。 An Isolation level is a feature of a transaction .隔离级别事务的一个特征。

So you, most probably, want to know what is the isolation level of current transaction ?所以你很可能想知道当前事务的隔离级别是多少? Hence you, most probably, do not manage this level by your code.因此,您很可能不会通过您的代码管理这个级别。 In this case it is managed by DBMS default or current settings.在这种情况下,它由 DBMS 默认或当前设置管理。

One of possible ways to explore it is described here : 这里描述探索它的一种可能方法:

try {
    session = getSessionFactory().openSession();
    txn = session.beginTransaction();
    session.doWork(new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {
            LOGGER.debug("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();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM