views:

305

answers:

1

I have a JSF 2.0 application that I would like to start adding validators for. A basic overview of the architecture of the app is as follows.

I have Managed Backing Beans that contain instances of my JPA annotated classes and EJB's. The EJB's are responsible for accessing the database transactionally. The JPA annotated classes are valuebound to my facelets (and use the EJB's for db access).

I would like to potentially use Bean validation and write custom constraints, however this will mean I have to add those constraints to my JPA annotated classes. This seems to me like it is violating my separation of concerns. (Mixing presentation/validation with the JPA annotated classes/DAOs) Is it better to not use Bean validation in this case? Is my structure flawed? Is there a preferred way of doing this that I do not know about?

Thanks!

+1  A: 

Validation is part of your business logic and hence must be present in your domain model which are your persistence entities. So there is absolutely nothing wrong in having them within your JPA entities.

Validations don't belong to presentation because even if you change your presentation layer (say you're gonna expose a bunch of web services on your EJBs), the validation still needs to be there.

Chandru