Question

I have some SessionBeans in a JEE Application and like to use BeanValidation to validate my Parameters. So the whole validation process is generic and encapsulated in one place.

The only disadvantage I see is that the client get's an EJBException and has to unwrap the main Exception. Are there some more problems or dirty things I don't see or even a better way to do it?

Was it helpful?

Solution

Make ConstraintViolationException an ApplicationException.

If you don't have it yet, create a ejb-jar.xml file (in /WEB-INF if ejbs are packaged in a war, in /META-INF otherwise):

<ejb-jar>
    <assembly-descriptor>
        <application-exception>
            <exception-class>javax.validation.ConstraintViolationException</exception-class>
            <rollback>true</rollback>
        </application-exception>
    </assembly-descriptor>
</ejb-jar>

You can do it for EJB 3.0 or above

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top