• Post Reply Bookmark Topic Watch Topic
  • New Topic

whereto use setRollbackOnly

 
william kane
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell when we need to use setRollbackOnly when we have the can call rollback when something fails?I am aware that setRollbackOnly will eventually prevent the transaction from commiting towards the end of the transaction.I would like to know a typically scenario where it would be used.
What are the activities that are executed in a transactional code even after a transaction is known to be doomed?
Thanks in advance
William
 
sammaiah kyatham
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi william kane,
Iam not directly using Java's Transactions API. Iam using BC4J Framework for EJBs. Iam using rollback process, if any one of the operation fails within a transaction.
 
Nadeem Awad
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know a typically scenario where it would be used.

Dear William,
If you have multiple beans that are paricipating in the same transaction, usually the bean that started the transaction will either call commit or rollback - in case of BMT - to end the transaction. And you can only do that once, which means that you can't rollback a transaction that is already rolled back. So if a bean that is called from another bean that started the transaction, it can mark the transaction for rollback using the setRollbackOnly method, so the caller bean would know and rollback that transaction, because it can't commit it. Now suppose that the second bean marks the transaction for rollback before it calls a third bean. The third bean should know whether that transaction is marked for rollback or not, before it starts to execute its own business logic, and waste time and resources.
[ July 13, 2005: Message edited by: Nadeem Awad ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may help.
http://www.coderanch.com/t/76842/Websphere/Transaction-Rollback-not-rolling-back
 
william kane
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So if a bean that is called from another bean that started the transaction, it can mark the transaction for rollback using the setRollbackOnly method, so the caller bean would know and rollback that transaction, because it can't commit it.


Thanks all for the response.But that is exactly my question why would I 'mark' a transaction for rollback when i can go ahead and rollback the transaction.Why would I want other beans participating in the transaction to execute code in the first place when i can rollback the transaction from the caller bean?
Hope I am clear with my question
Thanks,
William
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi William,


Thanks all for the response.But that is exactly my question why would I 'mark' a transaction for rollback when i can go ahead and rollback the transaction.Why would I want other beans participating in the transaction to execute code in the first place when i can rollback the transaction from the caller bean?

Because sometimes you simply cannot rollback your transaction. If you�re implementing CMT, then you have no way to get a reference to the current transaction object. J2EE forbids developer to interfere with transactions in this case, because the container will demarcate and set the transaction boundaries. Again you might face the peculiar situation that your application throws a business exception (and as you might know the container won�t rollback the current transaction in this case) but you have no way to get a reference to the current transaction object and rollback it yourself. The only work around is to call setRollBackOnly method and mark the transaction for rollback, allowing the container to do the rollback automatically. It makes a lot of sense isn�t it?
Regards.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!