Posted: Fri Jun 28, 2002 3:20 am Post subject: Transactions, JMS sessions and Session EJBs
Novice
Joined: 10 Apr 2002 Posts: 13
Hi
I have a particularly pertinent question that I have been trawling the web to answer with no success. The scenario is as follows:
I have a Session EJB (container managed transactions) that puts several messages on a queue. For each message, a database entry is created. If the 'unit of work' fails for any reason (e.g. database failure, JMS provider failure) during the process, the database should be rolled back and the messages should not be put on the queue.
Two session beans are involved (both with container managed transactions).
The Correspondence Session bean puts a List of messages on a queue one by one using a single session.:
// get a tracking number
.....
// put the message on the queue ObjectMessage requestMessage = session.createObjectMessage();
requestMessage.setObject(request);
sender.send(requestMessage);
}
// commit the jms unit of work
session.commit();
The UpdateAccount Session Bean creates a database entry for every request sent (using the tracking number as a foreign key)
The scenario I want to be able to avoid is this:
1) The Correspondence Session bean puts the messages on the queue
2) The Account Session bean creates entries in the database but fails for some reason. The transaction is rolled back
3) The messages still persist on the queue
i.e.The messages should not be committed to the JMS Queue until the session bean method commits.
I understand that distributed transactions may be a solution to a problem of this nature.
What I would like to know is: surely the SessionBean should automatically enlist the JMS session's transactional context in its context and thus rollback JMS session's transaction if the session beans transaction fails. In other words I should not have to call session.commit() on the JMS Session.
Am I missing the mark here or do you have any resources that you can share with me to help solve this problem?
(We are writing to the EJB 1.1 spec, using Websphere 4.0.2 as a container and MQSeries as the messaging resource)
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum