The getRollbackOnly() method returns true if the current transaction has been marked
for rollback. This information can be used to avoid executing work that would not be
committed anyway. For example, if an exception is thrown and captured within an
enterprise bean method, getRollbackOnly() can be used to determine whether the exception
caused the current transaction to be rolled back. If it did, there is no sense in
continuing the processing. If it did not, the EJB has an opportunity to correct the problem
and retry the task that failed. Only expert EJB developers should attempt to retry
tasks within a transaction. Alternatively, if the exception did not cause a rollback (i.e.,
getRollbackOnly() returns false), a rollback can be forced using the setRollback
Only() method.
Regards,
Prajakta
Doubt 1 - suppose a bean 1 calls bean 2 method . bean 1 method is running in a transaction that gets propagated to bean 2 method. now if a system exception occurs , container will MARK TRANSACTION FOR ROLLBACK.does mark transaction for rollback means container automatically calls EJBContext.setRollbackOnly() method ?
Yes, I guess you don't mean bean provider, but business logic of a certain bean calls EJBContext.setRollBackOnly(), right?Doubt 2 - will EJBContext.getRollBackOnly() returns true for both when container marks transaction for rollback and when the bean provider do EJBContext.setRollBackOnly() ?
Doubt 3 - how can getRollBackOnly() tell me that exception say X caused transaction to be rolled back ?
Doubt 4 - Frits , couldnt understand your last point viz. "if a transaction is rolled back (by the container) it will only happen in the bean where the transaction was started (by the container) "?
Yes, I guess you don't mean bean provider, but business logic of a certain bean calls EJBContext.setRollBackOnly(), right?
The container can not rollback the transaction in Bean 2 because the transaction was started in Bean 1. I just meant to say that rollback is initiated at the same place as where the transaction was started.
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|