Whereas EntityManagerFactoryUtils.closeEntityManager() will check if EntityManager is open before trying to close it, SessionFactoryUtils.closeSession() doesn't check if session is open.

As a consequence, if EntityManager is closed when entering closeEntityManager(), nothing will happen, whereas if Session is closed when entering closeSession(), a log ERROR will be generated (because of "org.hibernate.SessionException: Session was already closed") (tested with Spring 5.2 + Hibernate 5.1).

Maybe we could have a common behaviour between both classes ?

See related commit for EntityManagerFactoryUtils : https://github.com/spring-projects/spring-framework/commit/928f5423af2f64ca9578801adaa8c9612500b952


Context : - module spring-orm - class org.springframework.orm.jpa.EntityManagerFactoryUtils - class org.springframework.orm.hibernate5.SessionFactoryUtils

Comment From: ghusta

Thanks @jhoeller 👍