如何关闭使用JPA 1.0的Hibernate bean验证? [英] How do you turn off Hibernate bean validation with JPA 1.0?

查看:457
本文介绍了如何关闭使用JPA 1.0的Hibernate bean验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JPA 1.0环境中,如何关闭Hibernate 3.x的bean验证?



我用persistence.xml尝试了几件事情:

 < persistence-unit name =bbstatstransaction-type =RESOURCE_LOCAL> 
<属性>

数据库的东西

< property name =hibernate.validator.autoregister_listenersvalue =false/>
< / properties>
< validation-mode> NONE< / validation-mode>
< / persistence-unit>

最后一个导致

  org.xml.sax.SAXParseException:cvc-complex-type.2.4.a:从元素'validation-mode'开始找到无效的内容。 '{http://java.sun.com/xml/ns/persistence\":jta-data-source,http://java.sun.com/xml/ns/persistence\":non-jta-数据源,http://java.sun.com/xml/ns/persistence\":mapping-file,http://java.sun.com/xml/ns/persistence\":jar-file,http ://java.sun.com/xml/ns/persistence:class,http://java.sun.com/xml/ns/persistence\":exclude-unlisted-classes,http://java.sun .com / xml / ns / persistence:properties}。 

但上述工作没有任何作用。任何人都可以告诉我如何在JPA 1.0实现上做到这一点?

解决方案 javax.persistence。 validation.mode 属性是JPA 2.0的标准属性之一。它不会指望它在JPA 1.0环境中工作。实际上,假设你使用的是Hibernate Validator 4,我的建议是从类路径中删除JAR(我不确定Hibernate Validator的配置设置如果你使用的是Hibernate Validator 3,那么在插入或更新之前,以下应该禁止生成的DDL和实体验证中的约束支持:

 < property name =hibernate.validator.apply_to_ddlvalue =false/> 
< property name =hibernate.validator.autoregister_listenersvalue =false/>

但是从类路径中删除JAR也很简单。



如果您遇到更具体的问题,请提供更具体的细节(包括Hibernate验证器的版本)。



h3>


  • Hibernate Annotations参考指南中的第4章其他模块
  • Hibernate Validator 4.0.1.GA 参考指南 Hibernate Validator 3.1.0.GA 参考指南

  • JPA 2.0规范


    • 3.6.1.1启用自动验证

    • 9.4.3持久性单元属性
    • >


    How do you turn off bean validation with Hibernate 3.x in a JPA 1.0 environment?

    I tried several things with persistence.xml:

    <persistence-unit name="bbstats" transaction-type="RESOURCE_LOCAL">
      <properties>
    
        DB stuff
    
        <property name="javax.persistence.validation.mode" value="none" />
        <property name="hibernate.validator.autoregister_listeners" value="false" />
      </properties>
      <validation-mode>NONE</validation-mode>
    </persistence-unit>
    

    The last one causing

    org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'validation-mode'. One of '{"http://java.sun.com/xml/ns/persistence":jta-data-source, "http://java.sun.com/xml/ns/persistence":non-jta-data-source, "http://java.sun.com/xml/ns/persistence":mapping-file, "http://java.sun.com/xml/ns/persistence":jar-file, "http://java.sun.com/xml/ns/persistence":class, "http://java.sun.com/xml/ns/persistence":exclude-unlisted-classes, "http://java.sun.com/xml/ns/persistence":properties}' is expected.
    

    But nothing of the above work. Can anyone tell me how to do it on a JPA 1.0 implementation?

    解决方案

    The javax.persistence.validation.mode property is one of the standardized property from JPA 2.0. It wouldn't expect it to work in a JPA 1.0 environment.

    Actually, assuming you're using Hibernate Validator 4, my suggestion would be to remove the JAR from the class path (I'm not sure the configuration settings from Hibernate Validator 3 still apply).

    And if you are using Hibernate Validator 3, the following should disable the support of constraints inside the generated DDL and entity validation before an insert or updated:

    <property name="hibernate.validator.apply_to_ddl" value="false"/>
    <property name="hibernate.validator.autoregister_listeners" value="false"/>
    

    But removing the JAR from the class path would also be straight forward.

    If you're facing a more specific problem, please provide more specific details (including the version of Hibernate Validator).

    References

    这篇关于如何关闭使用JPA 1.0的Hibernate bean验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆