0

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.

Sachin Mhetre
  • 4,465
  • 10
  • 43
  • 68

2 Answers2

0

How about this?

Session session = getSessionFactory().openSession();

session.doSomethingWorthwhile(new Worthwhile() {
    @Override
    public void execute(Connection connection) {
    //Do something great with SQL here
    }
}
James McGuigan
  • 107
  • 1
  • 6
0

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).

Augusto
  • 28,839
  • 5
  • 58
  • 88