简体   繁体   中英

Hibernate/JPA/Seam - Validate an Entity Programmatically?

I have an entity in my JBoss Seam-based project that makes use of Hibernate Validator annotations throughout. 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支持编程用法,例如,参见《 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM