有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java禁用特定方法的Hibernate验证

我想禁用特定方法中的hibernate验证。例如,将验证保留为正常保存,并禁用它们以在不使用验证方法的情况下保存。是否可以通过一些注释来实现这一点

我知道它可以在具有以下属性的配置中禁用:

<Validation-mode> NONE </ validation-mode>

我实际上只是在带有@Valid注释的控制器上对表单错误进行验证。要插入到数据库中,我不需要

我的有效解决方案:

LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
...
Properties jpaProperties = new Properties();
jpaProperties.put("javax.persistence.validation.mode", "NONE");
factory.setJpaProperties(jpaProperties);

共 (1) 个答案

  1. # 1 楼答案

    尝试使用Validating Groups

    Groups allow you to restrict the set of constraints applied during validation. This makes for example wizard like validation possible where in each step only a specified subset of constraints get validated. The groups targeted are passed as var-args parameters to validate, validateProperty and validateValue.