diff --git a/spring-webflow/src/main/java/org/springframework/webflow/persistence/HibernateFlowExecutionListener.java b/spring-webflow/src/main/java/org/springframework/webflow/persistence/HibernateFlowExecutionListener.java index 446811c1..445b65a7 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/persistence/HibernateFlowExecutionListener.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/persistence/HibernateFlowExecutionListener.java @@ -83,6 +83,9 @@ public class HibernateFlowExecutionListener extends FlowExecutionListenerAdapter private static final boolean hibernate3Present = ClassUtils.isPresent("org.hibernate.connection.ConnectionProvider", HibernateFlowExecutionListener.class.getClassLoader()); + private static final boolean hibernate5Present = ClassUtils.isPresent("org.hibernate.boot.model.naming.PhysicalNamingStrategy", + HibernateFlowExecutionListener.class.getClassLoader()); + private static final Method openSessionMethod = ReflectionUtils.findMethod(SessionFactory.class, "openSession"); @@ -91,6 +94,8 @@ public class HibernateFlowExecutionListener extends FlowExecutionListenerAdapter private static final Method currentSessionMethod = ClassUtils.getMethod(SessionFactory.class, "getCurrentSession"); + private static final Method closeSessionMethod = ReflectionUtils.findMethod(Session.class, "close"); + /** * The name of the attribute the flow {@link Session persistence context} is indexed under. @@ -174,7 +179,7 @@ public class HibernateFlowExecutionListener extends FlowExecutionListenerAdapter }); } unbind(hibernateSession); - hibernateSession.close(); + ReflectionUtils.invokeMethod(closeSessionMethod, hibernateSession); } } @@ -245,8 +250,16 @@ public class HibernateFlowExecutionListener extends FlowExecutionListenerAdapter } private void bind(Session session) { - Object sessionHolder = (hibernate3Present ? - new org.springframework.orm.hibernate3.SessionHolder(session) : new SessionHolder(session)); + Object sessionHolder; + if (hibernate3Present) { + sessionHolder = new org.springframework.orm.hibernate3.SessionHolder(session); + } + else if (hibernate5Present) { + sessionHolder = new org.springframework.orm.hibernate5.SessionHolder(session); + } + else { + sessionHolder = new SessionHolder(session); + } TransactionSynchronizationManager.bindResource(sessionFactory, sessionHolder); }