EJB programming & troubleshooting: XA transaction to rollback to a savepoint
We have an MDB which picks message from a queue and calls a stateless session bean to processes the request. Both the MDB and Session bean have the transaction flag set as "Required". The session bean calls a DB2 stored procedure and based on the status of processing, it builds a success or error response XML message which has to be subsequently written to a response queue. In the stored proc, if any business error is encountered we have send this error as an XML to response queue. The intended flow in such a case is - 1. DB operations have to rolled back 2. Queue operations have to be committed (request message is read and response message is delivered) To achieve this, we tried declaring a SAVEPOINT in stored procedure and doing a ROLLBACK to SAVEPOINT in case of errors. But in this case we getting an error saying Savepoint cannot be used in a global transaction. Can anyone help as to how to do this. I am using WAS6.0 and DB2 as database.
- Posted by: Sriram S
- Posted on: March 25 2009 05:15 EDT
- Re: XA transaction to rollback to a savepoint by Mohammad Nour El-Din on March 31 2009 14:43 EDT
- Re: XA transaction to rollback to a savepoint by shreenee josh on April 09 2009 09:00 EDT
- Re: XA transaction to rollback to a savepoint by shreenee josh on June 02 2009 06:15 EDT
It is better to make the session bean method marked as for "Requires New" for the transaction support, so the whole DB operations initiated from the session bean are all done in one transaction regardless the one started with the message consumption in the MDB.
It is better to make the session bean method marked as for "Requires New" for the transaction support, so the whole DB operations initiated from the session bean are all done in one transaction regardless the one started with the message consumption in the MDB.If we make the Session bean's transaction property as "Requires New", then all DB operations will get committed. However, if there is a problem in the MDB soon after the call to the session bean (we have to put the response message in a queue and assume if this fails), then we will end up in an Inconsistent state - DB is committed but response message could not be delivered. The customer is demanding that even if a DB validation fails, he wants the response message to tell him that error.
It is not clear where do you rollback the transaction i.e. in proc or in session bean ... Have you tried this : Proc: Proc will manage the DB transaction entirely 1. you start a new transaction inside proc 2. set the save point 3. validate the request 4. commit / rollback the transaction 5. pass the result back to the session bean Session Bean: Propagate the result back to MDB. Since Proc handles all the transaction you can exit the call normally. MDB: Based on the result you can either rollback the transaction (i.e. mark it for rollback) and send the response message. Not sure if I have missed out anything. Please let me know what you find out.
will you please care to let us know how did you manage to resolve the problem?