aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Distributed Transactions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Distributed Transactions" Watch "Distributed Transactions" New topic
Author

Distributed Transactions

Bahadur Shah
Greenhorn

Joined: Feb 20, 2007
Posts: 18
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

Joined: Apr 18, 2009
Posts: 2234


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 .)




Save India From Corruption - Anna Hazare.
Bahadur Shah
Greenhorn

Joined: Feb 20, 2007
Posts: 18
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

Joined: May 09, 2010
Posts: 2
I have the same problem .Has any body found any solution to it
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

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

Joined: Feb 20, 2007
Posts: 18
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

Joined: Apr 16, 2008
Posts: 2187
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

Joined: Feb 20, 2007
Posts: 18
I created this test servlet just to test the application and do a POC
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Distributed Transactions