SpringSessionSynchronization's beforeCompletion unbinds after disconnect failure as well
Issue: SPR-13089
This commit is contained in:
		
							parent
							
								
									11401bd5e4
								
							
						
					
					
						commit
						8c337a48a9
					
				|  | @ -1,5 +1,5 @@ | ||||||
| /* | /* | ||||||
|  * Copyright 2002-2014 the original author or authors. |  * Copyright 2002-2015 the original author or authors. | ||||||
|  * |  * | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with the License. |  * you may not use this file except in compliance with the License. | ||||||
|  | @ -112,6 +112,7 @@ public class SpringSessionSynchronization implements TransactionSynchronization, | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public void beforeCompletion() { | 	public void beforeCompletion() { | ||||||
|  | 		try { | ||||||
| 			Session session = this.sessionHolder.getSession(); | 			Session session = this.sessionHolder.getSession(); | ||||||
| 			if (this.sessionHolder.getPreviousFlushMode() != null) { | 			if (this.sessionHolder.getPreviousFlushMode() != null) { | ||||||
| 				// In case of pre-bound Session, restore previous flush mode. | 				// In case of pre-bound Session, restore previous flush mode. | ||||||
|  | @ -119,13 +120,15 @@ public class SpringSessionSynchronization implements TransactionSynchronization, | ||||||
| 			} | 			} | ||||||
| 			// Eagerly disconnect the Session here, to make release mode "on_close" work nicely. | 			// Eagerly disconnect the Session here, to make release mode "on_close" work nicely. | ||||||
| 			session.disconnect(); | 			session.disconnect(); | ||||||
| 
 | 		} | ||||||
|  | 		finally { | ||||||
| 			// Unbind at this point if it's a new Session... | 			// Unbind at this point if it's a new Session... | ||||||
| 			if (this.newSession) { | 			if (this.newSession) { | ||||||
| 				TransactionSynchronizationManager.unbindResource(this.sessionFactory); | 				TransactionSynchronizationManager.unbindResource(this.sessionFactory); | ||||||
| 				this.holderActive = false; | 				this.holderActive = false; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public void afterCommit() { | 	public void afterCommit() { | ||||||
|  |  | ||||||
|  | @ -112,6 +112,7 @@ public class SpringSessionSynchronization implements TransactionSynchronization, | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public void beforeCompletion() { | 	public void beforeCompletion() { | ||||||
|  | 		try { | ||||||
| 			Session session = this.sessionHolder.getSession(); | 			Session session = this.sessionHolder.getSession(); | ||||||
| 			if (this.sessionHolder.getPreviousFlushMode() != null) { | 			if (this.sessionHolder.getPreviousFlushMode() != null) { | ||||||
| 				// In case of pre-bound Session, restore previous flush mode. | 				// In case of pre-bound Session, restore previous flush mode. | ||||||
|  | @ -119,13 +120,15 @@ public class SpringSessionSynchronization implements TransactionSynchronization, | ||||||
| 			} | 			} | ||||||
| 			// Eagerly disconnect the Session here, to make release mode "on_close" work nicely. | 			// Eagerly disconnect the Session here, to make release mode "on_close" work nicely. | ||||||
| 			session.disconnect(); | 			session.disconnect(); | ||||||
| 
 | 		} | ||||||
|  | 		finally { | ||||||
| 			// Unbind at this point if it's a new Session... | 			// Unbind at this point if it's a new Session... | ||||||
| 			if (this.newSession) { | 			if (this.newSession) { | ||||||
| 				TransactionSynchronizationManager.unbindResource(this.sessionFactory); | 				TransactionSynchronizationManager.unbindResource(this.sessionFactory); | ||||||
| 				this.holderActive = false; | 				this.holderActive = false; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public void afterCommit() { | 	public void afterCommit() { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue