You can do one the following:
- use bean managed transactions to call rollback or commit on the user
transaction, depending on status
- use client managed transactions to call rollback or commit on the user
transaction, depending on status
- use container managed transactions and call setRollbackOnly() on the
session context before you return (sample bellow)
- use container managed transactions and throw a runtime exception (in order
to rollback)
MySessionBeanMethod()
{
myEntityBean1.updateNum1(num1);
myEntityBean2.updateNum2(num2);
int status = sendMessageToExternalSystem(msg);
if (status == 0) {
// make sure that transaction is rolled back
m_ctx.setRollbackOnly();
}
}
But you are not safe with any of them. The entity bean updates will most
likely hit the database when the container (or you) decides to commit. They
may fail, and you will get a rollback any way - but the external system is
already commited. You can get it halfway close to 2-phase commit, by
implementing the SessionSynchronization interface. The best way to minimize
the risk window is of cause to assure that the resource manager of your
external system can participate in the distributed transaction initiated by
the containers transaction coordinator.
/Johan
-----Original Message-----
From: A mailing list for Enterprise JavaBeans development
[mailto:[EMAIL PROTECTED]]On Behalf Of Bill Leonard
Sent: den 26 augusti 2001 19:31
To: [EMAIL PROTECTED]
Subject: Session Bean Transactions
I have a Session Bean. It performs 3 actions inside one of its methods. 2
of the actions are updates to Entity Beans. The 3rd action is sending a
synchronous message to an external system. I want to have these 3 actions
performed in a transaction. I can see how the 2 entity bean updates will be
managed in the transaction; I don't know how to tell the container that the
transaction failed if the return value from sending a message to an external
system indicates failure.
So, if I have the following method on the Session Bean, MySessionBean:
MySessionBeanMethod()
{
myEntityBean1.updateNum1(num1);
myEntityBean2.updateNum2(num2);
int status = sendMessageToExternalSystem(msg);
if (status == 0)
// make sure that transaction is rolled back
}
I can specify the following transaction attributes in the deployment
descriptor:
MySessionBean's MySessionBeanMethod: Requires New
MyEntityBean1's updateNum1 method: Requires
MyEntityBean2's updateNum2 method: Requires
How do I ensure that if the MySessionBeanMethod(0 fails, that the whole
transaction is rolled back?
Thx,
Bill
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".