title: Enabling hibernate validation fail_fast in java config
body: <p>I am using hibernate-validator 5.1.2.Final and Spring 4.0.6.RELEASE and want to make use of fail-fast so that when I have configured an annotation with multiple constraints, they are not all executed and only the first error message is returned.</p>
  
  <pre><code>@MultipartFileNotEmpty
  @CsvFile
  @Documented
  @Constraint(validatedBy = { })
  @Target(ElementType.FIELD)
  @Retention(RetentionPolicy.RUNTIME)
  public @interface OrderCsv {
  
      String message() default "";
  
      Class&lt;?&gt;[] groups() default {};
  
      Class&lt;? extends Payload&gt;[] payload() default {};
  }
  </code></pre>
  
  <p>From looking at the <a href="https://docs.jboss.org/hibernate/validator/5.0/reference/en-US/html/chapter-bootstrapping.html#section-provider-specific-settings" rel="nofollow">Hibernate Validator</a> docs it appears I can enable fail_fast at a global level, but I am unsure how to enable this within Java config. My current hibernate configuration looks like:</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  @ComponentScan(basePackages="uk.co.project")
  public class HibernateConfig {
  
      final static String JDBC_URL = "jdbc:mysql://localhost:3306/";
      final static String DRIVER_CLASS = "com.mysql.jdbc.Driver";
  
      @Autowired
      private Environment environment;
  
      @Bean
      public DataSource dataSource() {
  
          BasicDataSource dataSource = new org.apache.commons.dbcp2.BasicDataSource();
          dataSource.setDriverClassName(DRIVER_CLASS);
          dataSource.setUsername(environment.getProperty("datasource.username"));
          dataSource.setPassword(environment.getProperty("datasource.password"));
          dataSource.setUrl(JDBC_URL + environment.getProperty("datasource.database"));
          dataSource.setInitialSize(10);
  
          return dataSource;
      }
  
      @Bean
      public LocalSessionFactoryBean sessionFactory() {
  
          LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
          sessionFactory.setDataSource(dataSource());
          sessionFactory.setPackagesToScan(new String[] { "uk.co.project.models" });
          sessionFactory.setHibernateProperties(hibernateProperties());
  
          return sessionFactory;
      }
  
      @Bean
      public HibernateTransactionManager transactionManager() {
  
          HibernateTransactionManager txManager = new HibernateTransactionManager();
          txManager.setSessionFactory(sessionFactory().getObject());
  
          return txManager;
      }
  
      @Bean
      public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
  
          return new PersistenceExceptionTranslationPostProcessor();
      }
  
      Properties hibernateProperties() {
          return new Properties() {
  
              private static final long serialVersionUID = 1L;
  
              {
                  setProperty("hibernate.hbm2ddl.auto", "validate");
                  setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
                  setProperty("hibernate.globally_quoted_identifiers", "true");
                  setProperty("hibernate.show_sql", "true");
              }
          };
      }
  
  }
  </code></pre>
  
  <p>I have tried adding <code>setProperty("hibernate.validator.fail_fast", "true");</code> to my <code>hibernateProperties</code> but that did not work. I would appreciate any pointers on how to enable fail_fast within my hibernate java config.</p>