This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes JMS and JDBC In a single transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "JMS and JDBC In a single transaction" Watch "JMS and JDBC In a single transaction" New topic
Author

JMS and JDBC In a single transaction

Gagan Tiwari
Ranch Hand

Joined: Jun 10, 2008
Posts: 71
Hi All,
I am having an application which is Spring based. (With no application or web server)

Now I need to read the records from the Database Table (Oracle) and put the message on the Queue (MQ).
But since these are two diffrent activity, how can we gurantee the Treansaction?

Please provide a way for this.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

Normally, one uses an XA driver to include the two operations - database and queue writing. I've never used one outside an application server, but it seems like it should be allowed.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Gagan Tiwari
Ranch Hand

Joined: Jun 10, 2008
Posts: 71
Hi,
Can you please provide an example (Sample Code) for the same?
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371
How XA driver commits two operations separately ?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

Gagan,
An example of hwat? Creating an XA driver in the spring config? Something else?

Kri,
The driver "polls" each resource to see if it is ready to commit.
Gagan Tiwari
Ranch Hand

Joined: Jun 10, 2008
Posts: 71
Thanks for the prompt response.

By example I meant sample code using Spring to have a JMS Operation and the JDBC in a single transaction.

I have searched a lot but unable to find the same.
Also in many post (On the Web) I have read that using Spring JTA transaction is not so god approach.
Kindly suggest
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371
The driver "polls" each resource to see if it is ready to commit.

Hi Jeanne, Whether driver "polls" each resource by transaction manager? If 1st JDBC transaction succeds, but 2nd JMS transaction fails, how it rollback both the transaction ?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Two Phase Commit

I believe you have to have an XA-aware JDBC driver to use XA - so I'd assume the driver would internally be able to do the rollback.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371
Whether we have to commit individually each transaction (or) single 'commit' commits both the transaction ?
Prabhakar Reddy Bokka
Ranch Hand

Joined: Jul 26, 2005
Posts: 189

Hope there will not be 2 commits in this case.

Data fetched from Database,
Put the message into MQ
On successful response from MQ Commit Database.

That completes the total transaction successfully.

This can be done using UserTransaction normally in web applications, So we can do that in Spring also.

Look at the link webpage

If yours is a standalone java application...

Set your auto commit false,
Fetch the data from database,
send the message to MQ,
after successful response from MQ, commit database.

SCJP 5, SCWCD 5
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371
If data is fetched from database1 and data is updated to database2, Whether we need separate commmit for each database transaction?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JMS and JDBC In a single transaction
 
Similar Threads
Dispose Window & jar
Back Button & Mouse Risk click
Accept compresed requests in tomcat
useBean
Study material of IBM test 286