Reputation: 167
I use JAX-RS to update an entity and I have a ValidationException mapper to handle validation errors.
In my JAX-RS method, I delegate the entity's update to an EJB method that uses internally EntityManager#merge to do the job.
Everything works fine but when I have a validation constraint error, instead of having a ValidationException which is then handled by my JAX-RS wrapper, I have instead a RollbackException which wraps my ValidationException. Therefore my exception wrapper is not called.
I thought of several ways to fix that :
I am looking for the best way to handle such problem. How would you do that ?
Thanks,
F.D
Upvotes: 2
Views: 166
Reputation: 19129
If you want to use the mapper approach and all changes are made via JAX-RS, I'll probably use JAX-RS Bean Validation support. You might then even be able to disable the JPA life-cycle based validation (using 'validation-mode' NONE).
In the end it will come down to how your application is structured and what your preferences are.
Upvotes: 1