I have a JDBC Connection
object which I want to convert into Hibrenate Session
.
Is there any way by which I can achieve this?
I am tried googling, but I'm getting result vice versa.
I have a JDBC Connection
object which I want to convert into Hibrenate Session
.
Is there any way by which I can achieve this?
I am tried googling, but I'm getting result vice versa.
How about this?
Session session = getSessionFactory().openSession();
session.doSomethingWorthwhile(new Worthwhile() {
@Override
public void execute(Connection connection) {
//Do something great with SQL here
}
}
You have to use the SessionFactory
to create a session with the connection. Call SessionFactory.openSession(Connection)
As the javadoc says, it's better to provide a custom ConnectionProvider
(but depends on your scenario).
I've used this in the past when I had to use a connection that was opened with the username/password of each user (good old days).