Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling Hibernate Validation on save/update with Hibernate 3.6.0.Final

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).

like image 625
egervari Avatar asked Dec 07 '10 19:12

egervari


People also ask

What is Hibernate validation?

Hibernate Validator allows to express and validate application constraints. The default metadata source are annotations, with the ability to override and extend through the use of XML. It is not tied to a specific application tier or programming model and is available for both server and client application programming.

What is the difference between javax validation and Hibernate Validator?

The Javax bean validation API provides the following most frequently used annotations. The Hibernate validator provides the following commonly used annotations for validation. In case of product or project development we must use both the annotations for bean validation.

Is Hibernate Validator thread safe?

Validating constraintsValidator instances are thread-safe and may be reused multiple times.

What is JPA Validator?

Data validation is a common task that occurs in all layers of an application, including persistence. The Java™ Persistence API (JPA) 2.0 provides support for the Bean Validation API so that data validation can be done at run time.


1 Answers

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.

like image 166
axtavt Avatar answered Oct 22 '22 14:10

axtavt