Rot*_*tem 7 java sql-server hibernate transactions isolation-level
我在 MSSQL 2005、2008、2012 中使用 hibernate 3.6。
我想设置会话创建的事务的隔离级别,但是我找不到有关 in 的任何信息。
这是我的代码
Session sess = factory.openSession();
Transaction tx = null;
try {
tx = sess.beginTransaction();
// do some work
...
tx.commit();
}
catch (RuntimeException e) {
if (tx != null) tx.rollback();
throw e; // or display error message
}
finally {
sess.close();
}
Run Code Online (Sandbox Code Playgroud)
我想做这样的事情
sess.beginTransaction(1|2|4|8);
Run Code Online (Sandbox Code Playgroud)
那可能吗?
谢谢你。
我刚刚找到了一个适合我的解决方案
if (forceReadCommitted) {
this.session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
connection.setTransactionIsolation(2);
}
});
}
Run Code Online (Sandbox Code Playgroud)
但您可以注意到这是针对整个连接而不是针对特定事务。可能还有更好的解决方案。
| 归档时间: |
|
| 查看次数: |
3036 次 |
| 最近记录: |