Skip to content

TransactionSynchronizationUtils.triggerBeforeCompletion() is swallowing IllegalStateException [SPR-2883] #7571

@spring-projects-issues

Description

@spring-projects-issues

Josh Moore opened SPR-2883 and commented

If the synchronization throws an exception on beforeCompletion() then things get quirky. Specifically, SpringSessionSynchronization.beforeCompletion() has this block:
if (this.newSession) {
// Default behavior: unbind and close the thread-bound Hibernate Session.
TransactionSynchronizationManager.unbindResource(this.sessionFactory); // THROWS HERE
this.holderActive = false;
if (this.hibernateTransactionCompletion) {
// Close the Hibernate Session here in case of a Hibernate TransactionManagerLookup:
// Hibernate will automatically defer the actual closing until JTA transaction completion.
// Else, the Session will be closed in the afterCompletion method, to provide the
// correct transaction status for releasing the Session's cache locks.
SessionFactoryUtils.closeSessionOrRegisterDeferredClose(this.sessionHolder.getSession(), this.sessionFactory);
}
}

My code is causing an IllegalStateException on unbindResource() (working to find out what's causing that), which gets logged in TransactionSynchronizationUtils (below) but doesn't throw:

  public static void triggerBeforeCompletion() {
	for (Iterator it = TransactionSynchronizationManager.getSynchronizations().iterator(); it.hasNext();) {
		TransactionSynchronization synchronization = (TransactionSynchronization) it.next();
		try {
			synchronization.beforeCompletion();
		}
		catch (Throwable tsex) {
			logger.error("TransactionSynchronization.beforeCompletion threw exception", tsex);
		}
	}
}

Since the registering of close in SpringSessionSynchronization isn't getting called, the transaction isn't getting committed, which means...

I'm getting return values (entity with id = k) but there's no entity with primary key k in the db. Weirdness.

Thanks, guys.
Josh.


Affects: 2.0 final

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)status: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions