本文介绍了在使用Hibernate 3.6.0.Final保存/更新时禁用Hibernate验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚开始升级一个使用Hibernate 3.5.6.Final的应用程序到3.6.0.Final,并且有几个hickups。最后的hickup我找不到解决方案。
3.6.0.Final似乎在通过Hibernate保存/更新对象时自动启用bean验证。这是非常糟糕的,因为我的一些测试不会打扰所有的属性设置 - 他们只是不需要。我真的不认为要设置每个'描述'字段和无数其他字段只是为了遵从任意验证。
这将迫使我花费在我所有的测试中都有效的对象(我现在有超过1300个功能测试)。坦率地说,这是毫无意义的,因为我确信所有的验证都发生在MVC中,并且目前没有其他方法可以将数据导入数据库。
我也不希望通过验证我的bean两次 - 一次在MVC中,然后在Hibernate中再次验证性能。这在我的情况下并不需要。
有没有办法可以解决这个问题?我使用Spring和常规Hibernate映射文件,而不是JPA(我不喜欢所有注释)。
code> persistence.xml :
< validation-mode> NONE< / validation -mode>
或将该属性添加到 hibernate.cfg.xml
:
< property name =javax.persistence.validation.mode> none< / property>
请参阅以获取更多选项。
I just started upgrading an application that used Hibernate 3.5.6.Final to 3.6.0.Final, and there has been several hickups. The last hickup I can't find a solution for.
3.6.0.Final seems to automatically turn on bean validation when an object is saved/updated through Hibernate. This is very bad because some of my tests don't bother setting all the properties - they just aren't needed. I honestly don't see the point to set every 'description' field and countless other fields just to comply with some arbitrary validation.
This is going to force me to spend hours making valid objects in all of my tests (I have over 1300 functional tests now). And frankly, it would be pointless because I am certain that all validation is happening in the MVC and there are no other ways to get data into the database currently.
I also don't want to incur a performance hit by validating my beans twice - once in the MVC, and then another time within Hibernate. It's just not needed in my case.
Is there a way I can turn this off? I am using Spring and regular Hibernate mapping files, not JPA (I dislike all the annotations).
解决方案
Add the following to persistence.xml
:
<validation-mode>NONE</validation-mode>
or add the property to hibernate.cfg.xml
:
<property name="javax.persistence.validation.mode">none</property>
See 23.1.2. Configuration for more options.
这篇关于在使用Hibernate 3.6.0.Final保存/更新时禁用Hibernate验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!