• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on context.setRollbackOnly()

 
Mayuri Roi
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("");
}
=============================
 
clive jordan
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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!