Aug 8th, 2011, 02:26 AM
java.lang.IllegalStateException: Cannot deactivate transaction synchronization - not
[LEFT]I am facing an issue with spring transaction manager.The issue goes like this
I have an application from where I launch a spring job(everything juns in the same jvm).My application has its own database tables to be populated.
My application is using its own org.springframework.jdbc.datasource.DataSourceTran sactionManager .Spring batch uses its own org.springframework.jdbc.datasource.DataSourceTran sactionManager. The commit issued from my application gives the following error..
java.lang.IllegalStateException: Cannot deactivate transaction synchronization - not active
at org.springframework.transaction.support.Transactio nSynchronizationManager.clearSynchronization(Trans actionSynchronizationManager.java:314)
at org.springframework.transaction.support.Transactio nSynchronizationManager.clear(TransactionSynchroni zationManager.java:449)
at org.springframework.transaction.support.AbstractPl atformTransactionManager.cleanupAfterCompletion(Ab stractPlatformTransactionManager.java:1008)
So ideally in this scenario where I have 2 similar transaction managers what should I do inorder to avoid the above error. I tried setting the TransactionDefinition to PROPAGATION_NESTED and TransactionSynchronization to SYNCHRONIZATION_NEVER in my application. After this the application started committing the appln specific tables but the spring batch specific tables entries where not getting committed properly..I tried setting the same transaction attributes in the sping batch job xml also..but then there was commit problem with my application code.
Could any one please help on this issue.
What should be the right way to execute these kind of applications where I have multiple/identical datasource transaction managers.
Aug 11th, 2011, 03:00 AM
You are probably going to have a lot of headaches if you have 2 transactions managers and need to use them both at the same time. The particular problem you have encountered is that only one of them is allowed to register synchronizations for a given transaction (there is a flag I think that you can set to disable one of them, but that might not be what you want). I'm not sure why you should be seeing that, but it is only the start of what you could get into. I would recommend using a single DataSource anyway, or at least a single TransactionManager if that isn't possible.
Aug 11th, 2011, 12:19 PM
Thanks for the reply.........
We created a single ApplicationContext to load the dataSource and transactionManager and passed the same into the 'public ClassPathXmlApplicationContext(String configLocations, ApplicationContext parent) throws BeansException' during job launching so that the same dataSource and transactionManager is getting used for spring batches also.
So the issue is resolved by using a common ds and tx mgr...