Skip to content

Commit 1a0006d

Browse files
author
graeme
committed
fix for bug where subflow attempted to close already closed hibernate session
git-svn-id: https://svn.codehaus.org/grails/trunk@6710 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
1 parent 083c55f commit 1a0006d

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/web/org/codehaus/groovy/grails/webflow/persistence/SessionAwareHibernateFlowExecutionListener.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,32 @@ public void sessionCreated(RequestContext context, FlowSession session) {
6969
public void sessionEnded(RequestContext context, FlowSession session, AttributeMap output) {
7070
if (isPersistenceContext(session.getDefinition())) {
7171
final Session hibernateSession = (Session) session.getScope().remove(HIBERNATE_SESSION_ATTRIBUTE);
72-
Boolean commitStatus = session.getState().getAttributes().getBoolean("commit");
73-
if (Boolean.TRUE.equals(commitStatus)) {
74-
try {
75-
if(TransactionSynchronizationManager.hasResource(localSessionFactory)) {
76-
SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(localSessionFactory);
77-
sessionHolder.addSession(hibernateSession);
78-
}
79-
localTransactionTemplate.execute(new TransactionCallbackWithoutResult() {
80-
protected void doInTransactionWithoutResult(TransactionStatus status) {
81-
localSessionFactory.getCurrentSession();
82-
// nothing to do; a flush will happen on commit automatically as this is a read-write
83-
// transaction
72+
if(hibernateSession.isOpen()) {
73+
Boolean commitStatus = session.getState().getAttributes().getBoolean("commit");
74+
if (Boolean.TRUE.equals(commitStatus)) {
75+
try {
76+
if(TransactionSynchronizationManager.hasResource(localSessionFactory)) {
77+
SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(localSessionFactory);
78+
sessionHolder.addSession(hibernateSession);
79+
}
80+
localTransactionTemplate.execute(new TransactionCallbackWithoutResult() {
81+
protected void doInTransactionWithoutResult(TransactionStatus status) {
82+
localSessionFactory.getCurrentSession();
83+
// nothing to do; a flush will happen on commit automatically as this is a read-write
84+
// transaction
85+
}
86+
});
87+
} finally {
88+
if(TransactionSynchronizationManager.hasResource(localSessionFactory)) {
89+
SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(localSessionFactory);
90+
sessionHolder.removeSession(hibernateSession);
8491
}
85-
});
86-
} finally {
87-
if(TransactionSynchronizationManager.hasResource(localSessionFactory)) {
88-
SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(localSessionFactory);
89-
sessionHolder.removeSession(hibernateSession);
90-
}
9192

93+
}
9294
}
95+
unbind(hibernateSession);
96+
hibernateSession.close();
9397
}
94-
unbind(hibernateSession);
95-
hibernateSession.close();
9698
}
9799
}
98100

0 commit comments

Comments
 (0)