Question

Hibernate has deprecated the connection() because they think the framework is so awesome that no-one will ever need the connection. And no, this is NOT the same thing as providing the connection, unless you are coming from Haskell. Anyways, I have a better idea to get rid of hibernate: a Connection wrapper arounds the hibernate session so I can pass the session around as a connection. I heard there is a way to get the connection with reflection. Does anyone know where I can get a wrapper like that?

public class SessionConnection implements Connection {

   private final Session session;
   private final Connection conn;

   public SessionConnection(Session session) {
       this.session = session;
       this.conn = getConnectionFromStupidHibernate(session);
   }

   // delegate methods go here
}
Was it helpful?

Solution

If you're using spring, just use the same DataSource you use for your SessionFactory - don't design your app around hibernate, fit hibernate into your design

OTHER TIPS

You need a SessionFactory and a ConnectionProvider -- see Hibernate: Providing Connections.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top