如何从休眠会话获取jdbc连接? [英] How to get jdbc connection from hibernate session?

查看:114
本文介绍了如何从休眠会话获取jdbc连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从hibernate session中获得jdbc连接。hibernate session
中有一个方法,例如session.connection();但它已被弃用。我知道这仍然有效,但我不想使用已弃用的方法,因为我确定他们必须为此提供一些替代方法?
http://docs.jboss.org/hibernate/orm /3.5/api/org/hibernate/Session.html 连接方法API说使用org.hibernate.jdbc.Work为此目的,但我没有找到任何示例?

  session.doWork解决方案

(new Work(){
@Override
public void execute(Connection connection)throws SQLException {
// connection,finally!
}
});


I want to get jdbc connection from hibernate session.There is method inside hibernate session i.e session.connection(); but it has been deprecated. i know this works still but i dont want to use deprecated method as i am sure they must have provide some alternative for this? At http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/Session.html connection method api says using org.hibernate.jdbc.Work for this purpose but i dont find any example for that?

解决方案

Here is how you can use it:

session.doWork(new Work() {
    @Override
    public void execute(Connection connection) throws SQLException {
        //connection, finally!
    }
});

这篇关于如何从休眠会话获取jdbc连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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