Domanda

After putting hibernate-validator.jar and javax.validation-api.jar in my classpath the my old validation turned off and org.springframework.dao.DataIntegrityViolationException is replaced by org.hibernate.exception.ConstraintViolationException which wraps SQL exception that is coming from table constraints and this is causing a lot of issues.

It automatically turned JSR-303 validation on so it doesn't validate anything anymore.

I have to put this two jars to be able to upgrade Jersey to 2.4, it has dependency on these two jars.

Putting these properties into hibernate.properties file doesn't help, hibernate simply ignores them but it loads the properties on start-up

loaded properties from resource hibernate.properties: {hibernate.validator.apply_to_ddl=false,hibernate.validator.autoregister_listeners=false etc}

javax.persistence.validation.mode=none
hibernate.validator.autoregister_listeners=false
hibernate.validator.apply_to_ddl=false

I am using Spring 3.2.4 with SessionFactory and mapping resources from hbm.xml files with constraints in it, hibernate 3.6.9.final, hibernate-validator 5.0.final, javax.validator-api 1.1.0.Final

I just can't figure out how to enable spring validation when hibernate.validator in my classpath, any help will be much appreciated.

È stato utile?

Soluzione 2

Adding hibernate validator to the classpath turns off hibernate core validation, so I had to add this property to turn it back on

<prop key="hibernate.check_nullability">true</prop>

Altri suggerimenti

You can disable Bean Validation by setting javax.persistence.validation.mode to none in your hibernate.cfg.xml (or persistence.xml when working with JPA).

Just out of interest, you seem to have constraint annotations on your model (otherwise you shouldn't see a ConstrainViolationException, so I'm wondering why you don't want to validate them?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top