How to get jdbc connection from hibernate session? [duplicate]

I want to get jdbc connection from hibernate session.There is method inside hibernate session i.e session.connection(); but it has been deprecated. i know this works still but i dont want to use deprecated method as i am sure they must have provide some alternative for this? At http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/Session.html connection method api says using org.hibernate.jdbc.Work for this purpose but i dont find any example for that?


Solution 1:

Here is how you can use it:

session.doWork(new Work() {
    @Override
    public void execute(Connection connection) throws SQLException {
        //connection, finally!
    }
});

Solution 2:

Try this:

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