title: Spring Hibernate validator not working but javax is
body: <p>Having some trouble with Spring Validation and the Hibernate Validator.</p>
  
  <p>I am using Spring 4 and Hibernate Validator 5, my problem is that the javax annotations are acting properly but it looks like the Hibernate annotations are not getting invoked.</p>
  
  <p>Here is my controller</p>
  
  <pre><code>@RequestMapping(method= RequestMethod.POST)
  @ResponseStatus(HttpStatus.CREATED)
  public void create(@RequestBody @Valid CreatePlantCommand command, BindingResult bindingResult, HttpServletResponse response){
  
      if (bindingResult.hasErrors()) {
          // do something
      }
  
      // do work
  
      // should set the location header on new requests
      String location = ServletUriComponentsBuilder.fromCurrentRequest()
              .pathSegment("{code}").buildAndExpand(code)
              .toUriString();
  
      response.setHeader("Location", location);
  }
  </code></pre>
  
  <p>and the command object</p>
  
  <pre><code>public class CreatePlantCommand {
  
      @NotNull
      private Integer code;
  
      @Length(min = 1, max = 5)
      //@Max(5)
      private String description;
  
      public int getCode() {
          return code;
      }
  
      public void setCode(int code) {
          this.code = code;
      }
  
      public String getDescription() {
          return description;
      }
  
      public void setDescription(String description) {
          this.description = description;
      }
  }
  </code></pre>
  
  <p>The NotNull and Max (its commented out right now) are working, but Length seems to be completely ignored. If I use Size, it works, if I use any Hibernate annotation its ignored.</p>
  
  <p>I am using the LocalValidatorFactoryBean from Spring</p>
  
  <pre><code>&lt;bean id='validator' class='org.springframework.validation.beanvalidation.LocalValidatorFactoryBean'/&gt;
  </code></pre>
  
  <p>Why would the Hibernate Validations not be applied?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Continuing to try and understand what is happening here.</p>
  
  <p>I have noticed the NotEmpty validation is the only one that works. I can put it on the description field and not send it, and I will get the error. If I put, Email, CreditCard or Url on the description and send it incorrect data, I don't get the error.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I've created a small project that is demonstrating some of this behavior. Its on my bitbucket repo at <a href="https://bitbucket.org/joeyoung/hibernate-validation-problems" rel="nofollow">https://bitbucket.org/joeyoung/hibernate-validation-problems</a>.</p>
  
  <p>The Form object has 4 public properties, two are commented out, that use the @Length and @Email validators. </p>
  
  <pre><code>public class Form {
  
      @Length(max=10)
      public String name;
  
      @Email
      public String email;
  
  //  @Range(min=18)
  //  public Integer age;
  
  //    @CreditCardNumber
  //    public String creditCard;
  }
  </code></pre>
  
  <p>If I post this json;</p>
  
  <pre><code>{
    "name":"adafasdfasfdsafd",
    "email":"adf",
    "age":1,
    "creditCard":"123456"
  }
  </code></pre>
  
  <p>To this controller</p>
  
  <pre><code>@RestController
  @RequestMapping("/form")
  public class FormController {
  
      @RequestMapping(method = RequestMethod.POST, consumes = "application/json")
      public List&lt;FieldError&gt; submitForm(@RequestBody @Valid Form form, BindingResult result) {
  
          if(result.hasErrors()) {
              return result.getFieldErrors();
          }
  
          return null;
      }
  }
  </code></pre>
  
  <p>No errors are returned.</p>
  
  <p>If I uncomment the @Range field and Post again, I get @Email and @Range errors, not @Length.</p>
  
  <p>I'm assuming I am doing something wrong and any guidance would be greatly appreciated.</p>
  
  <p>Server wise, I am using WebSphere Liberty 8.5 and my server.xml is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;server description="Default Liberty Server"&gt;
    &lt;!-- Enable features --&gt;
    &lt;featureManager&gt;
      &lt;feature&gt;jsp-2.2&lt;/feature&gt;
      &lt;feature&gt;jndi-1.0&lt;/feature&gt;
      &lt;feature&gt;jdbc-4.0&lt;/feature&gt;
      &lt;feature&gt;jpa-2.0&lt;/feature&gt;
      &lt;feature&gt;localConnector-1.0&lt;/feature&gt;
      &lt;feature&gt;beanValidation-1.0&lt;/feature&gt;
    &lt;/featureManager&gt;
    &lt;!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" --&gt;
    &lt;httpEndpoint id="defaultHttpEndpoint" httpPort="9080" httpsPort="9443" /&gt;
    &lt;applicationMonitor updateTrigger="mbean" /&gt;
    &lt;application id="problems_war_exploded" location="C:\Users\jyoung\Code\hibernate-validation-problems\target\problems-0.0.1-SNAPSHOT" name="problems_war_exploded" type="war" context-root="/hibernate-validation-problems" /&gt;
  &lt;/server&gt;
  </code></pre>