• 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

Question on context.setRollbackOnly()

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between the following two if statements in an ejbCreate method of an entity bean? If I have setter methods BEFORE the 'if' statement what is the impact on them if 'if' condition is true?

=============================
if (someCondition) {
context.setRollbackOnly();
throw new someException("");
}
=============================
if (someCondition) {
throw new someException("");
}
=============================
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mayuri,

By calling context.setRollbackOnly() on a CMT bean, you ensure that the transaction will not complete and things should return to how they were before the transaction started. You are then throwing a checked exception which may (or may not) be of use to the client.

In your second example, you are just throwing an exception. This is probably a checked exception but in this case there is no guarantee that the system has not been updated. So although you are informing the client that something may have gone wrong, the system may *not* be in the same state it was prior to starting the transaction.

Cheers,
Clive
 
Mayuri Roi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Clive. Thank You!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic