Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you turn off Hibernate bean validation with JPA 1.0?

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?

like image 668
Kawu Avatar asked Aug 15 '10 18:08

Kawu


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.

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.

Is Hibernate Validator thread safe?

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


1 Answers

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

  • Chapter 4. Additional modules in the Hibernate Annotations reference guide
  • Hibernate Validator 4.0.1.GA Reference Guide
  • Hibernate Validator 3.1.0.GA Reference Guide
  • JPA 2.0 specification
    • 3.6.1.1 Enabling Automatic Validation
    • 9.4.3 Persistence Unit Properties
like image 189
Pascal Thivent Avatar answered Sep 23 '22 18:09

Pascal Thivent