This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Distributed Transactions

 
Bahadur Shah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to perform a distributed transaction in My Servlet.
My distributed transaction involves Updating to the DB and also publishing a message to a queue.
The queue is not present in my app server, where my Servlet is running.
It is there on a remote machine.

I'm using below code to achieve the same.
But I'm not getting the transactional behaviour working... That means
If I publish a message to queue and then if DB Operation fails, the transaction should roll back and the queue should not be having any contents.
But my queue is still showing me the contents...

Any glitches in my code???

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

To achive this behaviour you can go for the Transaction Attribute Mantadatory on to the caller .

(Mantadatory is for updating the Database contents ) and the queue method consiting of another Method .)



 
Bahadur Shah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please give some more details on how to achieve what you said?

I need to do this in my Servlet. I'm not using any EJB Components/Spring
 
ranjanabha bhattacharya
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the same problem .Has any body found any solution to it
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. use the XA versions of the implementations.
2. make sure you are using an XA driver.
3. Do not specify a transacted session..JTA user transactions are ignored by transacted sessions and you cannot include other resources in transactions when you use a transacted session for jms. Specify false in the first arg to connection.createSession() method.

The original code will not even compile. There is no publishMessage() method that accepts a bolean var.

For example



ram.
 
Bahadur Shah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried using false to not to use transacted session. But am still getting the same error

My code is like below. I am clueless what is missing.
I am using SAP NetWeaver Application Server

In my below code, Even after I rollback my JTA UserTransaction, the JMS operations are not rolling back.

 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any glitches in my code???


I would say there is a "glitch" in your design. Stuffing all of this transactional code in a servlet is questionable and in conflict with standard three-tier programming model.

Presentation tier

Business tier

Integration tier


Java servlets are for handling Presentation-oriented requirements via web server. Cramming business logic/data logic/transactional logic into servlet classes typically is not a very good design for anything mildly complex, e.g. distributed transactions.
 
Bahadur Shah
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created this test servlet just to test the application and do a POC
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic