@@ -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