|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2014 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -112,18 +112,21 @@ public void beforeCommit(boolean readOnly) throws DataAccessException {
|
112 | 112 |
|
113 | 113 | @Override
|
114 | 114 | public void beforeCompletion() {
|
115 |
| - Session session = this.sessionHolder.getSession(); |
116 |
| - if (this.sessionHolder.getPreviousFlushMode() != null) { |
117 |
| - // In case of pre-bound Session, restore previous flush mode. |
118 |
| - session.setFlushMode(this.sessionHolder.getPreviousFlushMode()); |
| 115 | + try { |
| 116 | + Session session = this.sessionHolder.getSession(); |
| 117 | + if (this.sessionHolder.getPreviousFlushMode() != null) { |
| 118 | + // In case of pre-bound Session, restore previous flush mode. |
| 119 | + session.setFlushMode(this.sessionHolder.getPreviousFlushMode()); |
| 120 | + } |
| 121 | + // Eagerly disconnect the Session here, to make release mode "on_close" work nicely. |
| 122 | + session.disconnect(); |
119 | 123 | }
|
120 |
| - // Eagerly disconnect the Session here, to make release mode "on_close" work nicely. |
121 |
| - session.disconnect(); |
122 |
| - |
123 |
| - // Unbind at this point if it's a new Session... |
124 |
| - if (this.newSession) { |
125 |
| - TransactionSynchronizationManager.unbindResource(this.sessionFactory); |
126 |
| - this.holderActive = false; |
| 124 | + finally { |
| 125 | + // Unbind at this point if it's a new Session... |
| 126 | + if (this.newSession) { |
| 127 | + TransactionSynchronizationManager.unbindResource(this.sessionFactory); |
| 128 | + this.holderActive = false; |
| 129 | + } |
127 | 130 | }
|
128 | 131 | }
|
129 | 132 |
|
|
0 commit comments