The exception ' org.hibernate.HibernateException: No Session found for current thread ' occurs if you incorrectly configured transaction demarcation using Spring.
Typically, Spring opens a session for you when your transaction begins, binds it to ThreadLocal, and reuses it throughout the transaction. When the transaction completes, the session closes (after it is reset). This way you do not need to make any calls in the SessionFactory class.
Usually people put @Transactional in a class (usually in a service) and configure Spring to start and end transactions when calling a method on this class.
Hans westerbeek
source share