开发者

Hibernate/JPA/Seam - Validate an Entity Programmatically?

开发者 https://www.devze.com 2023-02-06 12:01 出处:网络
I have an entity in my JBoss Seam-based project that makes use of Hibernate Validator annotations through开发者_JAVA百科out.Although I\'ve got directives in my JSF pages to require elements, etc. I\'d

I have an entity in my JBoss Seam-based project that makes use of Hibernate Validator annotations through开发者_JAVA百科out. Although I've got directives in my JSF pages to require elements, etc. I'd like to be able to do one last failsafe validation before calling entityManager.persist() and ending up with a validation exception.

Is there any way to validate the entity programmatically? I've never worked that deeply with Hibernate/JPA, so I'd love to hear any recommendations for getting this working. Thanks!


Bean Validation API supports programmatic usage, see, for example, Hibernate Validator Reference.


If you are using JSF, you can have the validation to occur before your business method is called. If you are not seeing this, I would review the setup, as it should happen automatically and you wouldn't need to manually perform the validation. But you can do that, as you can see in axtavt's answer.

0

精彩评论

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