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 a4a93251..630cc94e 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
@@ -51,10 +51,10 @@ import org.springframework.webflow.execution.RequestContext;
*
* The general data access pattern implemented here is:
*
- * - Create a new persistence context when a new flow execution with the 'persistenceContext' attribute starts
- *
- Load some objects into this persistence context
- *
- Perform edits to those objects over a series of requests into the flow
- *
- On successful flow completion, commit and flush those edits to the database, applying a version check if
+ *
- Create a new persistence context when a new flow execution with the 'persistenceContext' attribute starts
+ *
- Load some objects into this persistence context
+ *
- Perform edits to those objects over a series of requests into the flow
+ *
- On successful flow completion, commit and flush those edits to the database, applying a version check if
* necessary.
*
*
@@ -132,9 +132,9 @@ public class HibernateFlowExecutionListener extends FlowExecutionListenerAdapter
}
}
- public void sessionEnded(RequestContext context, FlowSession session, String outcome, AttributeMap output) {
+ public void sessionEnding(RequestContext context, FlowSession session, String outcome, MutableAttributeMap output) {
if (isPersistenceContext(session.getDefinition())) {
- final Session hibernateSession = (Session) session.getScope().remove(PERSISTENCE_CONTEXT_ATTRIBUTE);
+ final Session hibernateSession = getHibernateSession(session);
Boolean commitStatus = session.getState().getAttributes().getBoolean("commit");
if (Boolean.TRUE.equals(commitStatus)) {
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@@ -148,6 +148,9 @@ public class HibernateFlowExecutionListener extends FlowExecutionListenerAdapter
unbind(hibernateSession);
hibernateSession.close();
}
+ }
+
+ public void sessionEnded(RequestContext context, FlowSession session, String outcome, AttributeMap output) {
if (!session.isRoot()) {
FlowSession parent = session.getParent();
if (isPersistenceContext(parent.getDefinition())) {
diff --git a/spring-webflow/src/main/java/org/springframework/webflow/persistence/JpaFlowExecutionListener.java b/spring-webflow/src/main/java/org/springframework/webflow/persistence/JpaFlowExecutionListener.java
index 719f5c1f..d1b0701b 100644
--- a/spring-webflow/src/main/java/org/springframework/webflow/persistence/JpaFlowExecutionListener.java
+++ b/spring-webflow/src/main/java/org/springframework/webflow/persistence/JpaFlowExecutionListener.java
@@ -50,10 +50,10 @@ import org.springframework.webflow.execution.RequestContext;
*
* The general data access pattern implemented here is:
*
- * - Create a new persistence context when a new flow execution with the 'persistenceContext' attribute starts
- *
- Load some objects into this persistence context
- *
- Perform edits to those objects over a series of requests into the flow
- *
- On successful conversation completion, commit and flush those edits to the database, applying a version check if
+ *
- Create a new persistence context when a new flow execution with the 'persistenceContext' attribute starts
+ *
- Load some objects into this persistence context
+ *
- Perform edits to those objects over a series of requests into the flow
+ *
- On successful conversation completion, commit and flush those edits to the database, applying a version check if
* necessary.
*
*
@@ -120,9 +120,9 @@ public class JpaFlowExecutionListener extends FlowExecutionListenerAdapter {
}
}
- public void sessionEnded(RequestContext context, FlowSession session, String outcome, AttributeMap output) {
+ public void sessionEnding(RequestContext context, FlowSession session, String outcome, MutableAttributeMap output) {
if (isPersistenceContext(session.getDefinition())) {
- final EntityManager em = (EntityManager) session.getScope().remove(PERSISTENCE_CONTEXT_ATTRIBUTE);
+ final EntityManager em = getEntityManager(session);
Boolean commitStatus = session.getState().getAttributes().getBoolean("commit");
if (Boolean.TRUE.equals(commitStatus)) {
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@@ -134,6 +134,9 @@ public class JpaFlowExecutionListener extends FlowExecutionListenerAdapter {
unbind(em);
em.close();
}
+ }
+
+ public void sessionEnded(RequestContext context, FlowSession session, String outcome, AttributeMap output) {
if (!session.isRoot()) {
FlowSession parent = session.getParent();
if (isPersistenceContext(parent.getDefinition())) {
diff --git a/spring-webflow/src/test/java/org/springframework/webflow/persistence/HibernateFlowExecutionListenerTests.java b/spring-webflow/src/test/java/org/springframework/webflow/persistence/HibernateFlowExecutionListenerTests.java
index 82e78e8c..10874c17 100644
--- a/spring-webflow/src/test/java/org/springframework/webflow/persistence/HibernateFlowExecutionListenerTests.java
+++ b/spring-webflow/src/test/java/org/springframework/webflow/persistence/HibernateFlowExecutionListenerTests.java
@@ -118,6 +118,7 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
endState.getAttributes().put("commit", Boolean.TRUE);
flowSession.setState(endState);
+ hibernateListener.sessionEnding(context, flowSession, "success", null);
hibernateListener.sessionEnded(context, flowSession, "success", null);
assertEquals("Table should only have two rows", 2, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
assertSessionNotBound();
@@ -149,6 +150,7 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
endState.getAttributes().put("commit", Boolean.TRUE);
flowSession.setState(endState);
+ hibernateListener.sessionEnding(context, flowSession, "success", null);
hibernateListener.sessionEnded(context, flowSession, "success", null);
assertEquals("Table should only have three rows", 3, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
assertFalse(flowSession.getScope().contains("hibernate.session"));
@@ -174,6 +176,7 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel");
endState.getAttributes().put("commit", Boolean.FALSE);
flowSession.setState(endState);
+ hibernateListener.sessionEnding(context, flowSession, "success", null);
hibernateListener.sessionEnded(context, flowSession, "cancel", null);
assertEquals("Table should only have two rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
assertSessionNotBound();
@@ -192,6 +195,7 @@ public class HibernateFlowExecutionListenerTests extends TestCase {
EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel");
flowSession.setState(endState);
+ hibernateListener.sessionEnding(context, flowSession, "success", null);
hibernateListener.sessionEnded(context, flowSession, "cancel", null);
assertEquals("Table should only have three rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
assertFalse(flowSession.getScope().contains("hibernate.session"));
diff --git a/spring-webflow/src/test/java/org/springframework/webflow/persistence/JpaFlowExecutionListenerTests.java b/spring-webflow/src/test/java/org/springframework/webflow/persistence/JpaFlowExecutionListenerTests.java
index 2f8a5734..42d1c6d9 100644
--- a/spring-webflow/src/test/java/org/springframework/webflow/persistence/JpaFlowExecutionListenerTests.java
+++ b/spring-webflow/src/test/java/org/springframework/webflow/persistence/JpaFlowExecutionListenerTests.java
@@ -68,6 +68,7 @@ public class JpaFlowExecutionListenerTests extends TestCase {
endState.getAttributes().put("commit", Boolean.TRUE);
flowSession.setState(endState);
+ jpaListener.sessionEnding(context, flowSession, "success", null);
jpaListener.sessionEnded(context, flowSession, "success", null);
assertEquals("Table should only have two rows", 2, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
assertSessionNotBound();
@@ -99,6 +100,7 @@ public class JpaFlowExecutionListenerTests extends TestCase {
endState.getAttributes().put("commit", Boolean.TRUE);
flowSession.setState(endState);
+ jpaListener.sessionEnding(context, flowSession, "success", null);
jpaListener.sessionEnded(context, flowSession, "success", null);
assertEquals("Table should only have three rows", 3, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
assertFalse(flowSession.getScope().contains("hibernate.session"));
@@ -123,7 +125,8 @@ public class JpaFlowExecutionListenerTests extends TestCase {
EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel");
endState.getAttributes().put("commit", Boolean.FALSE);
flowSession.setState(endState);
- jpaListener.sessionEnded(context, flowSession, "cancel", null);
+ jpaListener.sessionEnding(context, flowSession, "cancel", null);
+ jpaListener.sessionEnded(context, flowSession, "success", null);
assertEquals("Table should only have two rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
assertSessionNotBound();
assertFalse(flowSession.getScope().contains("hibernate.session"));
@@ -141,7 +144,8 @@ public class JpaFlowExecutionListenerTests extends TestCase {
EndState endState = new EndState(flowSession.getDefinitionInternal(), "cancel");
flowSession.setState(endState);
- jpaListener.sessionEnded(context, flowSession, "cancel", null);
+ jpaListener.sessionEnding(context, flowSession, "cancel", null);
+ jpaListener.sessionEnded(context, flowSession, "success", null);
assertEquals("Table should only have three rows", 1, jdbcTemplate.queryForInt("select count(*) from T_BEAN"));
assertFalse(flowSession.getScope().contains("hibernate.session"));