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?
Spring opens a new Hibernate Session at the beginning of the request. These Sessions are not necessarily connected to the database. Every time the application needs a Session, it will reuse the already existing one.
Hibernate and JPA-based applications do not eliminate the need for JDBC. When you use Hibernate, all database interactions still occur with the JDBC APIs. Hibernate and JPA are actually built on top of the JDBC API.
When you don't close your Hibernate sessions and therefore do not release JDBC connections, you have what is typically called Connection leak. So, after a number of requests (depending on the size of your connection pool) the server will not be able to acquire a connection to respond your request.
Here is how you can use it:
session.doWork(new Work() { @Override public void execute(Connection connection) throws SQLException { //connection, finally! } });
Try this:
((SessionImpl)getSession()).connection()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With