• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JMS and JDBC In a single transaction

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author & internet detective
Posts: 42103
933
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Gagan Tiwari
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can you please provide an example (Sample Code) for the same?
 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How XA driver commits two operations separately ?
 
Jeanne Boyarsky
author & internet detective
Posts: 42103
933
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whether we have to commit individually each transaction (or) single 'commit' commits both the transaction ?
 
Ranch Hand
Posts: 198
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If data is fetched from database1 and data is updated to database2, Whether we need separate commmit for each database transaction?
 
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic