session.connection() deprecated on Hibernate?

Try This

((SessionImpl)getSession()).connection()

Actuly getSession returns Session Interface type, you should see what is the original class for the session, type cast to the original class then get the connection.

GOOD LUCK!


If session.connect() is now deprecated, how am I supposed to do that?

You have to use Session#doWork(Work) and the Work API, as mentioned in the Javadoc:

connection()
     Deprecated. (scheduled for removal in 4.x). Replacement depends on need; for doing direct JDBC stuff use doWork(org.hibernate.jdbc.Work); for opening a 'temporary Session' use (TBD).

You have some time before Hibernate 4.x but, well, using a deprecated API somehow looks like this:

alt text:)

Update: According to RE: [hibernate-dev] Connection proxying on the hibernate-dev list, it seems that the initial intention of the deprecation was to discourage the use of Session#connection() because it was/is considered as a "bad" API, but it was supposed to stay at that time. I guess they changed their mind...


You now have to use the Work API:

session.doWork(connection -> doSomething(connection)); 

Or, in Java < 8 :

session.doWork(
    new Work() {
        public void execute(Connection connection) throws SQLException 
        { 
            doSomething(connection); 
        }
    }
);