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??

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top