Question

I've a Remote SLSB that is deployed in OC4J.

This Session Bean uses TopLink which under some case throws oracle.toplink.essentials.exceptions.QueryException exception.

I am handling this exception this way:

public void slsbMethod()
{
   try
   {
      // oracle.toplink.essentials.exceptions.QueryException throws here 
   }catch(Exception ex)
   {
      // do nothing
   }
}

And I am calling this SLSB from a client that way:

try
{
    fooBarService.slsbMethod()
}catch(Exception ex)
{
    System.out.println("Exception calling the EJB server");
}

However I am handling this exception on the EJB, still I got the message Exception calling the EJB server printed!

How is this happening??

Was it helpful?

Solution

If the exception is coming from container-managed transaction code, then I would suggest using bean-managed transactions. With that, you can put the exception handling in the bean around the call to UserTransaction.commit. Alternatively, you could write an interceptor to begin the transaction, call InvocationContext.proceed(), and then commit the transaction and handle exceptions as you like. This is basically what the container is doing for you, but you can handle the commit exception as you like, and you can reuse the logic on other beans/methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top