• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

whereto use setRollbackOnly

 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may help.
https://coderanch.com/t/76842/Websphere/Transaction-Rollback-not-rolling-back
 
william kane
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic