oscar
oscar

Reputation: 1756

Disabling Hibernate Validation for specific methods

I want to disable hibernate validations in a specific method. For example conserve validations for normal save and disable them to saveWithoutValidation method. Is it possible to do this with some annotation?

I know it can be disabled in the configuration with the attribute:

<Validation-mode> NONE </ validation-mode>

I really just use the validations on controllers with @Valid annotation for form errors. To insert into database I do not need.

My valid solution:

LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
...
Properties jpaProperties = new Properties();
jpaProperties.put("javax.persistence.validation.mode", "NONE");
factory.setJpaProperties(jpaProperties);

Upvotes: 2

Views: 883

Answers (1)

user1134181
user1134181

Reputation:

Try using Validating Groups:

Groups allow you to restrict the set of constraints applied during validation. This makes for example wizard like validation possible where in each step only a specified subset of constraints get validated. The groups targeted are passed as var-args parameters to validate, validateProperty and validateValue.

Upvotes: 5

Related Questions