开发者

Should I use Bean Validation with EJB 3.1, JSF2.0 and JPA?

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 Man开发者_开发问答aged 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜