Hi all,
I have the following situation in a method of a Stateless EJB ( 3.0)
public void writeInDB(String userName,String password) throws UserNotFoundException {
// call a Local EJB method
User user = userDAO.updateUser(userName);
if ( user == null ) {
logDAO.write("User not found");
throw new UserNotFoundException("user not found");
}
}
The exception UserNotFoundException has the annotation @ApplicationException(rollback=true) inside
Well, from the cose above in case user==null I write a message "User not found" in the table and then I Throw an exception so the client, which calls the method "writeInDB" can understand better what's going on.
The problem is that throwing the exception UserNotFoundException the message "User not found" is not written in database because it is made a rollback.
So, is there any way to avoid this without using @ApplicationException(rollback=false) in the class UserNotFoundException ?
I need to write some message in a table in case something goes wrong.
Cheers.
zoster
Write to the table in a separate transaction. I don't know what logDAO is. But if it internally ends up invoking some bean method then just annotate that method to have REQUIRES_NEW transaction semantics.