title: Validation form in Spring using @Valid not work
body: <p>I want to validation my form, but this not work.
  My entity class</p>
  
  <pre><code>import java.io.Serializable;
  import java.util.Set;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Size;
  
  import org.hibernate.validator.constraints.Email;
  
  @Entity
  @Table(name = "users")
  public class User implements Serializable {
  
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue
      @Column(name = "id")
      private Integer id;
      @NotNull
      @Size(max = 20)
      @Column(name = "username")
      private String username;
      @NotNull
      @Size(max = 20)
      @Column(name = "password")
      private String password;
      @NotNull
      @Size(max = 20)
      @Column(name = "firstName")
      private String firstName;
      @NotNull
      @Size(max = 20)
      @Column(name = "lastName")
      private String lastName;
      @Size(min = 11, max = 11)
      @Column(name = "personalId")
      private String personalId;
      @Size(max = 40)
      @Column(name = "city")
      private String city;
      @Size(max = 40)
      @Column(name = "address")
      private String address;
      @NotNull
      @Email
      @Size(max = 30)
      @Column(name = "email")
      private String email;
      @Size(min = 9, max = 9)
      @Column(name = "phone")
      private String phone;
      @OneToMany(mappedBy = "user")
      private Set&lt;UserRole&gt; userRoleSet;
  }
  </code></pre>
  
  <p>adminList.jsp and form go to addAdmin page:</p>
  
  <pre><code>&lt;form action="addAdminForm" method="post"&gt;
      &lt;input type="submit" value="Dodaj administratora" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>addAdmin.jsp page formule:</p>
  
  <pre><code>    &lt;form:form action="addAdmin" modelAttribute="user" method="post"&gt;
      &lt;form:label path="username"&gt;Login: &lt;/form:label&gt;
      &lt;form:input path="username" /&gt;
      &lt;form:errors path="username" cssClass="error" /&gt;
      &lt;br /&gt;
      &lt;form:label path="password"&gt;Hasło: &lt;/form:label&gt;
      &lt;form:password path="password" /&gt;
      &lt;form:errors path="password" cssClass="error" /&gt;
      &lt;br /&gt;
      &lt;form:label path="firstName"&gt;Imię: &lt;/form:label&gt;
      &lt;form:input path="firstName" /&gt;
      &lt;form:errors path="firstName" cssClass="error" /&gt;
      &lt;br /&gt;
      &lt;form:label path="lastName"&gt;Nazwisko: &lt;/form:label&gt;
      &lt;form:input path="lastName" /&gt;
      &lt;form:errors path="lastName" cssClass="error" /&gt;
      &lt;br /&gt;
      &lt;form:label path="email"&gt;Email: &lt;/form:label&gt;
      &lt;form:input path="email" /&gt;
      &lt;form:errors path="email" cssClass="error" /&gt;
      &lt;br /&gt;
      &lt;input type="submit" value="Dodaj" /&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>    @RequestMapping(value = "/admin/addAdminForm", method = RequestMethod.POST)
  public ModelAndView goAddAdminForm() {
      ModelAndView mav = new ModelAndView("admin/addadmin");
      mav.addObject("user", new User());
      return mav;
  }
  
  @RequestMapping(value = "/admin/addAdmin", method = RequestMethod.POST)
  public String addAdmin(@Valid @ModelAttribute("user") User user,
          BindingResult result, Model model) {
      if (result.hasErrors()) {
          return "admin/addadmin";
      } else {
          userService.createUser(user);
          user = userService.findByUsername(user.getUsername());
          UserRole userRole = new UserRole("ROLE_ADMIN");
          userRole.setUser(user);
          userRoleService.createUserRole(userRole);
          return "redirect:/admin/adminlist";
      }
  }
  </code></pre>
  
  <p>When i try send empty formule i should get error messages <code>result.hasErrors()</code> not return error and my application go to else and try save user. Why @Valid not work?</p>