-
1. Re: Exceptions are being wrapped
aslak Sep 29, 2011 8:00 AM (in response to iapazmino)Could you provide a simple example ? EJBs + testclass
-
2. Re: Exceptions are being wrapped
iapazmino Sep 29, 2011 10:34 AM (in response to aslak)Hello Aslak, thank you for your reply. The following is a simple code which depicts the case.
I've got an eao which looks for something and throws an exception if its not found.
public class EmployeeEAO {
...
public Employee searchById(Long id) throws EntidadNoExisteException {
...
try {
return em.createQuery(query).getSingleResult();
} catch (NoResultException e) {
throw new EntidadNoExisteException("No existe un empleado con el id [" + id + "]");
}
}
}
The exception is just in order to translate actually...
public class EntidadNoExisteException extends RuntimeException {
...
}
The client when invokes this method catches the exception and manage it
public class ClientClass {
...
@EJB
private EmployeeEAO emp;
private PersonEAO per;
...
public Person getThisPerson(Long id) throws EntidadNoExisteException {
Person person = null;
try {
person = emp.searchById(id);
} catch (EntidadNoExisteException e) {
// This block is never reached
person = per.searchById(id); // This invocation might throw EntidadNoExisteException too
}
return person;
}
}
After the test is run the error line reads
Time elapsed: 0.391 sec <<< ERROR!
javax.ejb.EJBTransactionRolledbackException: No existe un empleado con el id [0234154789001]
I also put some logging in my disbelieve which confirmed it never reaches the catch block.
The test is really simple, it just invokes the client method in the test case and that's it.
-
3. Re: Exceptions are being wrapped
aslak Sep 29, 2011 10:01 AM (in response to iapazmino)Your injecting ClientClass in your TestClass, and it's the Exception between ClientClass and EmployeeDAO that does not work..?
-
4. Re: Exceptions are being wrapped
iapazmino Sep 29, 2011 10:33 AM (in response to aslak)Yes, the TestClass has an injected reference to the ClientClass, but the block not being executed is the catch inside ClientClass.getThisPerson. It never reaches that block and the exception is wrapped inside the EJBTransactionRolledbackException