session.connection()在Hibernate上弃用? [英] session.connection() deprecated on Hibernate?

查看:611
本文介绍了session.connection()在Hibernate上弃用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要能够获得休眠会话的相关 java.sql.Connection 。没有其他连接可以工作,因为此连接可能与正在运行的事务相关联。

We need to be able to get the associated java.sql.Connection of a hibernate session. No other connection will work, as this connection may be associated with a running transaction.

如果session.connection()现在已被弃用,我该怎么做?

If session.connection() is now deprecated, how am I supposed to do that?

推荐答案

您现在必须使用Work API:

You now have to use the Work API:

session.doWork(
    new Work() {
        public void execute(Connection connection) throws SQLException 
        { 
            doSomething(connection); 
        }
    }
);

或者,在Java 8中:

Or, in Java 8 :

session.doWork(connection -> doSomething(connection)); 

这篇关于session.connection()在Hibernate上弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆