• Post Reply Bookmark Topic Watch Topic
  • New Topic

I want to Rollback a transaction

 
ravi inguva
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
i have an stateless session bean, in that i have business method which removes all the entity beans related to a particular ID, but before deleting each entity i peform a validation, if that fails i want to roll back all the records which were deleted prior to the last failed validation
can you please tell me the better way of rolling back all the record
the two ways i know is
1. ebjcontext.setrollbackonly and
2. throwing a new system exception
can somebody guide me how to handle this situation for rolling back.
Thanks in Advace
Ravi.I
[ January 24, 2003: Message edited by: ravi inguva ]
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ravi inguva:

can you please tell me the better way of rolling back all the records
the two ways i know is
1. ebjcontext.setrollbackonly and
2. throwing a new system exception
can somebody guide me how to handle this situation for rolling back.

That's it. What is it that you find inadequate about either of those choices for rolling back a transaction?
Of course, for the rollback to work the way you intend, the transactional attributes will need to be properly set on your Entity Beans. In other words, all of your Entity Bean interaction needs to take place in the context of the same transaction.
In this case you should mark your Entity Beans with the transactional attribute "Required" and mark your Session Bean with "RequiresNew". In general I usually mark Entity Beans as "Required" unless they are Read-Only in which case I mark them as "NotSupported".
If properly configured, you should only have to rollback from your Session Bean in order to rollback all the Entity Bean interactions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!