I have the exact same problem that you have/had. If you see this can you please tell me how you solved it.
This happens because the container tries to invoke the method, but get a checked exception that the that's not declared in the method you're calling. If you declare the method in the remote interface of the entitybean as throws SomeException the UndeclaredThrowableException should go away.
BTW you can get the exception that caused UndeclaredThrowableException to be thrown by calling the getUndeclaredThrowableException method on the UndeclaredThrowableException
See the javadoc for more info on UndeclaredThrowable:
Thanks for your reply!
EJB is very new to me so I am not sure that I understand what you mean. In which method sould I declare an extra Exception?
I call a set method in my entity bean which only do the following:
public void setSystemLanguage(String systemLang)
this.systemLang = systemLang;
In the remoteinterface the method is declared like this:
public void setSystemLanguage( String systemLang )
When I for instance try to set a value that has to many characters to fit into the databasefield the ejbStore method throws an EJBexception that wraps a SQLException. The client only gets an UndeclaredThrowableException.
Thanks for the reply. The UndeclaredThrowableException originates from the proxy instance on the client side, because the error thrown by the container is not a subclass of the RemoteException (which is the onlydeclared exception on the remote interface). According to section 12.3.1 of the EJB1.1 Spec, the container should throw RemoteException in the case when an Exception other than an AppException occured in the implementation.
To put it differently. If I do not declare any exceptions in my EntityBean subclass, I should not get an UndeclaredThrowableException on the client side, but rather a RemoteException. To put it frankly, I think it is a bug in JBoss. The container is not throwing a RemoteException as it is required to do.
To be more exact:
case1: Bean Participating in existing transaction
When an exception occurs in the container which is not thrown by the EnityBean subclass (i.e. your cmp bean) the container should throw javax.transaction.TransactionRolledBackException (which extends java.rmi.RemoteException), and not javax.transaction.RollbackException as it is currently doing. If javax.transaction.TransactionRolledBackException is thrown, you will 1) Not get UndeclaredThrowableException ,2) Be able to check the root exception (e.g. SQLException) on the client and try to recover from it.
case2: Bean Creating new transaction
When an exception occurs in the container which is not thrown by the EnityBean subclass (i.e. your cmp bean) the container should throw java.rmi.RemoteException.
With javax.transaction.TransactionRolledBackException you will alse be able to check the root exception, which was an issue on another forum thread.
But then again, maybe I am just a bad spec reader:)
Thanks for your reply! :)
I use bmp and JBoss 2.2.2. What can I do so that I don´t get UndeclaredThrowableException?
I would think a feasable (and temporary!) workaround will be to add javax.transaction.RollbackException to the throws clause of all the set methods on your Remote Interfaces. This will allow the incorrect (IMHO) exception thrown by the container to be propagated to the client. Note however that this is not an elegant solution.
PS I would appreciate it if one of the lead developers can comment on my postings in this thread, as I think it may result in a bugfix. Or can someone tell me I am wrong and why!?