views:

33

answers:

2

I receive javax.ejb.TransactionRolledbackLocalException in Websphere 7 from the container and I wonder how is it possible to catch this exception? I have a timeout set in Websphere and get this message after this time. I run session beans.

I am trying to find what SQl statement was the cause of this exception. Where can i find that?

+1  A: 

A transaction is rolled back when one of two conditions are met:

  1. There is an exception in your code
  2. There is a timeout

Obviously, you can catch the exception in case #1 by wrapping the outermost code with a try{}catch(). But which code of yours is executed on timeout?

Unless your app server offers an API to attach a listener to such events, this is not possible. See the documentation which you received with the product or call the support for details.

[EDIT] If you want to see the SQL which actually causes the timeout, you have two options:

  1. You can use java.sql.DriverManager.setLogWriter(w); to log all SQL statements to a file. While this always works, it will create a lot of output and it will be hard to match this against the exception unless you can make sure you are the only one running requests.

  2. If you use an OR mapper (like Hibernate and such), you can enable logging for them. See here for Hibernate.

Aaron Digulla
Have you heard of such an API?
No, but that doesn't mean it doesn't exist. As I said: Check the docs.
Aaron Digulla
+1  A: 

As per Sun's docs Here's the bottom line guideline: If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception.

TransactionRolledbackLocalException is an unchecked exception and there is nothing you can do if it happens. You could catch it as Aaron Digulla suggests in his answer, but what is the point ?

If you catch it then you will be messing with the internals of the App Server. You will get an exception on the client and you can call getCause() on the exception you get on the client to properly notify the user.

You have two solutions

  1. Look at what is causing the timeout (Probably bad SQL)
  2. Increase the timeout
Romain Hippeau
The reason is that I want to find what SQL is causing the timeout and I cant find it. The exception object doesnt contain the bad SQL from what I know.
@user271858 If you look at the Stack Trace is it there ? If it is it got there by iterating through the exception chain. You can do this in your code (look here http://java.sun.com/docs/books/tutorial/essential/exceptions/chained.html )
Romain Hippeau
No, it isn't thats Í am afraid.
@user271858 In your question you are proposing a solution to a problem, but you are not describing the problem. Can you update your question by putting in the exact problem you are trying to solve. As in "I want to be able to see failed queries"
Romain Hippeau