When using HibernateDaoSupport class,I found that getSession().connection(); is deprecated.
What is another method,please,instead of this
When using HibernateDaoSupport class,I found that getSession().connection(); is deprecated.
What is another method,please,instead of this
现在我们必须使用 session.doWork() API:
session.doWork(
new Work() {
public void execute(Connection connection) throws SQLException
{
doSomething(connection);
}
}
);
我找到了以下解决方法来获取 Session 的连接而没有任何弃用。我很确定 Hibernate 的人不会允许这样做。
private static class WorkAround implements org.hibernate.jdbc.Work {
private Connection conn = null;
@Override
public void execute(Connection conn) throws SQLException {
this.conn = conn;
}
public Connection getConnection() {
return conn;
}
}
public static Connection getConnection(Session session) {
WorkAround wrk = new WorkAround();
session.doWork(wrk);
return wrk.getConnection();
}
我想在这里发布这个答案:session.connection() deprecated on Hibernate? ,但我看到我不允许这样做。
您可以使用 org.hibernate.internal.SessionImpl;
import org.hibernate.internal.SessionImpl;
public static class WorkAround {
public Connection getConnection(Session session){
SessionImpl sessionImpl = (SessionImpl) session;
return session.connection()
}
}