本文介绍了休眠验证器 - 不同的组创建,更新,删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用bean验证,特定的hibernate验证器实现是否可以将某些组定义为自动用于创建或更新等特定的crud操作?



或者是否有一些内部检查这些操作的hibernate组中? / div>

您可能正在寻找。您可以通过在SessionFactory上设置属性来设置属性,以指定在不同时间验证哪些组,如下所示:

 <属性名称= javax.persistence.validation.group.pre-坚持 > javax.validation.Default< /性> 
< property name =javax.persistence.validation.group.pre-update> javax.validation.Default< / property>
< property name =javax.persistence.validation.group.pre-remove>< / property>

如果您未指定任何内容,以上是默认配置。具体来说,在创建和更新时验证 javax.validation.Default 组。没有任何内容在删除时被验证。


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?

解决方案

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.

这篇关于休眠验证器 - 不同的组创建,更新,删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 13:13