I am facing with a problem. I have a managed bean where in case of an exception I want to show a message on screen. I have something like this:
public String create() {
try {
... //code where I save some records on database
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("UserCredentialsCreated"));
return "email-activation.xhtml";
} catch (ConstraintViolationException e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
return null;
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
return null;
}
}
The problem is that when an exception happens, I see the error on screen, but the rollback is not performed.
How can I do both things?