0

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Aliuk
  • 1,249
  • 2
  • 17
  • 32
  • Do you mean a DB rollback? The code you include is only related with the view layer, which is not responsible to manage DB transactions. – Aritz Aug 07 '16 at 16:34
  • Yes, I am talking about a DB rollback. I am thinking that probably the rollback is only done in EJB's. I'll try to put the code that makes the error inside a Stateless bean. – Aliuk Aug 07 '16 at 16:48
  • Are you managing the transaction yourself or through a `@Transactional` annotation? – Aritz Aug 07 '16 at 16:49
  • I am not doing anything with transactions, but I think that stateless beans by default create a transaction or join to the existing one if one exists. – Aliuk Aug 07 '16 at 16:56
  • In the end it was what I told. I just put the code with the error inside the same EJB that created the records on the database and now it does the rollback. – Aliuk Aug 07 '16 at 21:18

0 Answers0