Easy learning with example program codes

What is difference between openSession and getCurrentSession?

The SessionFactory.getCurrentSession() returns a session bound to a context. We don’t need to close this. We have to set hibernate.current_session_context_class to thread and then implement something like a servlet filter that opens the session. We can access that session anywhere else by using the SessionFactory.getCurrentSession(). thread

The SessionFactory.openSession() always opens a new session that we have to flush() and close() once we are done with the operations.

Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki