hibernate validator - different groups on create, update, delete

自闭症网瘾萝莉.ら 提交于 2019-12-20 01:05:32

问题


Using bean validation, particular hibernate validator implementation is it possible to define certain groups to automatically be used on certain crud operations like create or update?

or are there some build in hibernate groups that are internally checked for those operations?


回答1:


You're probably looking for "Hibernate event-based validation" under "ORM Integration". You can set properties to specify which groups to validate at different times by setting properties on the SessionFactory like so:

<property name="javax.persistence.validation.group.pre-persist">javax.validation.Default</property>
<property name="javax.persistence.validation.group.pre-update">javax.validation.Default</property>
<property name="javax.persistence.validation.group.pre-remove"></property>

The above is the default configuration if you don't specify anything. Specifically, the javax.validation.Default group is validated on creates and updates. Nothing is validated on deletes.



来源:https://stackoverflow.com/questions/16930623/hibernate-validator-different-groups-on-create-update-delete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!