Search code examples
primefacesejbstateless

ApplicationRollBackException not shown in primefaces messages


Currently one of my stateless class is throwing an exception annotated with applicationException with rollback=true. This exception is caught in the bean class and added successfully to the faces messages, but for some reason it is not shown.

My setup: bean->service (throw exception here) - ok bean->service->service (throw here) - failed

bean is annotated with: @Named @ViewScoped (omnifaces)

while service is Stateless.

Seems like session is lost on the second service. Any idea why?

Here is my exception class:

@ApplicationException(rollback = true)
public class BusinessException extends Exception

Solution

  • The solution seem rather weird note that: BusinessException extends Exception, so in my code I have:

    try {
       //..
    } catch (Exception e) {
      messages.error(e.getMessage());
    }
    

    But that doesn't work, but this does:

    try {
       //..
    } catch (BusinessException e1) {     
      messages.error(e1.getMessage());
    } catch (Exception e) {
      messages.error(e.getMessage());
    }
    

    The idea is to catch the BusinessException itself and not its parent. But I don't know why that is.