如何从休眠会话获取 jdbc 连接? [英] How to get jdbc connection from hibernate session?
问题描述
我想从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 但我没有找到任何示例?
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?
推荐答案
以下是它的使用方法:
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
//connection, finally!
}
});
这篇关于如何从休眠会话获取 jdbc 连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!