Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How EJB transactions are done? 1

Status
Not open for further replies.

hyperbug

Programmer
Aug 10, 2001
25
0
0
ES
Suppose there is a method named method_B which opens a jdbc connection directly using the jdbc API.

This method opens its connection with the autocommit attribute set to true and makes an insert.

This method was called from another method named method_A which has the transaction attribute set to required (TX_REQUIRED).

The method_A also calls a method_C that was not completed and throws an EJBexception.

method_A
{
try {
method_B();
method_C();
}
catch(EJBException e) { } etc..
}

the question is:

Does the container rollback the transaction did by method_A?
 
In your current example, the container will not rollback the transaction because you are catching the EJBException instead of letting it pass through to the container. If the container recieves an EJBException from your ejb then it will roll back all changes but if it never recieves the exception then it doesn't know anything is wrong. The other side effect of the container recieving an EJBException (or any exception that extends RuntimeException or RemotException) is that it will destroy the ejb in memory. If this is undesired then you will need to catch the exception and mark the transaction as a rollback yourself. This can be done by calling setRollbackOnly() on your ejb's EJBContext. You also need to make sure that you are using a JDBC driver that supports 2PC.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top