• 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

setRollBack()

 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In javax.transaction.UserTransaction, there is setRollbackOnly() method. Can some tell me when we should use this setRollbackOnly()method ?


------------------
Thanks,
Mike
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you have a question like this, you should first do a search on JavaRanch to see if anyone has asked this question before. In fact, right below on the page (on this thread) someone answered the same question.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Mike Yu
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kyle Brown:
When you have a question like this, you should first do a search on JavaRanch to see if anyone has asked this question before. In fact, right below on the page (on this thread) someone answered the same question.
Kyle


Hi Kyle,
That question was asked by myself and answered by Marco. I had a further question posted after Marco's anwser. The second question was not anwsered. This is why I posted the above question. Can you go to my previous question and give me an anwser? Many thanks!


------------------
Thanks,
Mike
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm... This might be reaching a bit. Someone else can probably come up with a better example. Personally, I think that it's probably there for symmetry with the EJB interface, but...
If you are using BMT, then sometimes you may be way deep inside of a transaction and discover that you need to roll the transaction back. Well, the problem is one of scope -- if you invoke a rollback() deep inside your call tree everything will proceed hunky-dory until later back up in the call tree someone tries to do a commit() -- and then they'll get an uninformative IllegalStateException thrown at the commit.
So instead, when you get to a point where you decide a transaction cannot commit (for instance, the spec talks about doing this prior to throwing an exception) you can mark the transaction as rollback only -- even if your code doesn't look to see the transaction state and tries to commit, it will still end up rolling back -- and the commit() will throw the slightly more meaningful "RollbackException".
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Mike Yu
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kyle Brown:
Hmmm... This might be reaching a bit. Someone else can probably come up with a better example. Personally, I think that it's probably there for symmetry with the EJB interface, but...
If you are using BMT, then sometimes you may be way deep inside of a transaction and discover that you need to roll the transaction back. Well, the problem is one of scope -- if you invoke a rollback() deep inside your call tree everything will proceed hunky-dory until later back up in the call tree someone tries to do a commit() -- and then they'll get an uninformative IllegalStateException thrown at the commit.
So instead, when you get to a point where you decide a transaction cannot commit (for instance, the spec talks about doing this prior to throwing an exception) you can mark the transaction as rollback only -- even if your code doesn't look to see the transaction state and tries to commit, it will still end up rolling back -- and the commit() will throw the slightly more meaningful "RollbackException".
Kyle



Thanks Kyle, your explanation gives me a meaningful picture. I still hope to see more examples from others.

------------------
Thanks,
Mike
 
reply
    Bookmark Topic Watch Topic
  • New Topic