Reputation: 113
When using HibernateDaoSupport class,I found that getSession().connection(); is deprecated.
What is another method,please,instead of this
Upvotes: 4
Views: 8693
Reputation: 1
You can use 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()
}
}
Upvotes: 0
Reputation: 1038
I have found the following workaround for getting Session's connection without any deprecation. I'm pretty sure Hibernate's people didn't meant to allow this.
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();
}
I wanted to post this answer here: session.connection() deprecated on Hibernate?, but I see I'm not allowed to.
Upvotes: 0
Reputation: 121998
Now we have to use session.doWork() API:
session.doWork(
new Work() {
public void execute(Connection connection) throws SQLException
{
doSomething(connection);
}
}
);
Refer also :session.connection() deprecated on Hibernate?
Upvotes: 2