12.11.2014 Views

web server - Borland Technical Publications

web server - Borland Technical Publications

web server - Borland Technical Publications

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Handling of EJB exceptions<br />

Options for continuing a transaction<br />

When a transaction is not marked for rollback, then the client has three options:<br />

■<br />

■<br />

Rollback the transaction.<br />

Pass the responsibility by throwing a checked exception or re-throwing the original<br />

exception.<br />

■<br />

Retry and continue the transaction. This can entail retrying portions of the<br />

transaction.<br />

When a client receives a checked exception for a transaction not marked for rollback,<br />

its safest course is to rollback the transaction. The client does this by either marking<br />

the transaction as “rollback only” or, if the client has actually started the transaction,<br />

calling the rollback method to actually rollback the transaction.<br />

The client can also throw its own checked exception or re-throw the original exception.<br />

By throwing an exception, the client lets other programs further up the transaction<br />

chain decide whether or not to abort the transaction. However, in general it is<br />

preferable for the code or program closest to the occurrence of the problem to make<br />

the decision about saving the transaction.<br />

Lastly, the client can continue with the transaction. The client can evaluate the<br />

exception message and decide if invoking the method again with different parameters<br />

is likely to succeed. However, you need to keep in mind that retrying a transaction is<br />

potentially dangerous. You have no knowledge of nor guarantee that the enterprise<br />

bean properly cleaned up its state.<br />

Clients that are calling stateless session beans, on the other hand, can retry the<br />

transaction with more confidence if they can determine the problem from the thrown<br />

exception. Because the called bean is stateless, the client does not have the problem<br />

of not knowing the state in which the bean left the transaction.<br />

Chapter 19: Transaction management 181

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!