Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

How to commit JDBC prior to JMS in a Transaction

 
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I work on two resources (JMS & JDBC). I use WebsphereUowTransactionManager. But JMS transactions are getting committed prior to the JMS transaction. This seems to be the default behavior. Is there a way to have a reverse behavior where JDBC is committed prior to JMS commit..??
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys any suggestions
 
Ranch Hand
Posts: 218
Hibernate Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spring supports this type of scenario, basically the scenario where database is committed before JMS is called "best effort strategy" for managing transaction involving JDBC & JMS without using JTA. If you are using the jms listener-container provided by Spring for consumption of messages, then for the acknowledge property you need to specify "transacted". In this case Spring will then synchronize with transaction started by local transaction manager like DataSourceTransactionManager. I am not very sure if it will work with WebsphereUowTransactionManager as it is implementation of JTA transaction manger from IBM. With WebsphereUowTransactionManager you also have a option of using JTA transactions.
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response.

I have a approach, which i need to test it out.

I plan to introduce a separate Transaction Boundary for JDBC within the JMS Transaction Boundary. By this way, i could commit/ rollback JDBC transaction before the JMS commit/rollback.

Do you think this approach would work out positively.
 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your approach should work, as Spring internally will also be doing something like this. However the downside is that you will have to write code for doing all this which can introduce potential bugs, cause maintainence issues & is not scalable if you have a lot of places in your app where JMS & database transactions need to work.

I would try to use Spring to do this for me & will revert back to writing code if Spring is not able to cater to the scenario.
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried various other configuration changes where i could make JDBC commit prior to JMS commit. I use JMSTemplate102 and tried using JTATransactionManager, WebSphereUowTransactionManager but nothin turned out to be helpful.
 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had got it working with jms listener container & DataSourceTransactionManager. Have shared configuration below. I am not very sure if it will work with JTA. In case you are not using XA transactions you can use DataSourceTransactionManager.


 
Ashwin Sridhar
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rishi,

Thanks for the response. I am using XA transaction along with JDBC. So i guess, in order to override the default approach of JMS-COMMIT-FIRST-FOLLOWED-BY-JDBC-COMMIT, i indeed have to go in for nexted transactions.

The approach i told is working, but it may not be the best approach i guess.
 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have 2 different databases that requires XA transactions. Basically a situation where 2 resource managers are being used require XA transactions. In case you are already using transactions then JMS can also participate in JMS transaction. In this case the "best effort strategy" of committing database before JMS is not required. For JTA to work you need to use XA aware resources (drivers for JDBC & connection factories for JMS).
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a single Database and a single Queue. I already use both of them within a transaction. My problem is, JMS gets committed first followed by JDBC. So application listening to queue reacts first and searchs for data in Database and ends up in No Data Found Exception. However , by redelivering the message in the queue, the issue is handled. But it is not what desired.

 
ranger
Posts: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, it sounds more to me that you need two transactions "nested"

You could do REQUIRES_NEW on the jdbc call. And when it comes back, then send the JMS Message within its own transaction.

Hope that helps.

Mark
 
Ashwin Sridhar
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI ,

Thats wat exactly i did. But there is a drawback in that approach. If the Jdbc Succeeds and Jms fails, i cannot make the JDBC to rollback.

So i made my Jdbc , a non - XA resource. So automatically JDBC commits prior to JMS.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a pretty nice way to solve the issue: http://do-on-it.blogspot.com/2012/02/spring-database-transactions-before.html
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!