• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Question on context.setRollbackOnly()

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Hi Clive. Thank You!
 
Whip out those weird instruments of science and probe away! I think it's a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic