25 November 2012

There's an issue with Spring Data Mongo when used in the context of an application with existing PlatformTransactionManager-based transaction management setup, where Spring's TransactionSynchronizationManager tries to find the bound Spring Data Mongo DB instance, but fails and throws an exception.

The issue is resolved, but you wouldn't know that if you checked the Spring Data MongoDB web site because there is no mention of the later releases. This issue is fixed in the latest releases, however, versions, 1.1.1.RELEASE.

If you're using Maven, you can specify the latest revision with the following Maven coordinates:

 <dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-mongodb</artifactId>
    <version>1.1.1.RELEASE</version>
  </dependency>

The error looks like this:

java.lang.IllegalStateException: No value for key [Mongo: localhost:27017] bound to thread [1128017935@qtp-1027055145-3]
at org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(TransactionSynchronizationManager.java:209) ~[spring-tx-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.transaction.support.ResourceHolderSynchronization.beforeCompletion(ResourceHolderSynchronization.java:69) ~[spring-tx-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCompletion(TransactionSynchronizationUtils.java:106) ~[spring-tx-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCompletion(AbstractPlatformTransactionManager.java:937) [spring-tx-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:738) [spring-tx-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) [spring-tx-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393) [spring-tx-3.1.1.RELEASE.jar:3.1.1.RELEASE]
 

Hat tip to the one and only Oliver Gierke for helping me with this!