title: Hibernate Validator is not working
body: <p><strong>I'm trying to validate field using JSR303, Hibernate validator. I'm using @NotEmpty annonation for that, and try to print simple error meassage. But it not working.</strong></p>
  
  <p><strong>Here is my User pojo class.</strong></p>
  
  <pre><code>package com.kalam.model;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.EnumType;
  import javax.persistence.Enumerated;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  import javax.validation.constraints.NotNull;
  
  import org.hibernate.validator.constraints.NotEmpty;
  
  @Entity
  @Table(name="User")
  public class User {
  
  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  private Long userId;
  
  @Column
  @NotEmpty(message="username can't be blank")
  private String UserName;
  
  @Column
  @NotEmpty(message="password can't be blank")
  private String Password;
  
  @Column
  @NotEmpty(message="Mobile can't be blank")
  private Integer MobileNo;
  
  public Integer getMobileNo() {
      return MobileNo;
  }
  
  public void setMobileNo(Integer mobileNo) {
      MobileNo = mobileNo;
  }
  
  @Enumerated(EnumType.ORDINAL)
  private Role userRole;
  
  public Long getUserId() {
      return userId;
  }
  
  public void setUserId(Long userId) {
      this.userId = userId;
  }
  
  public String getUserName() {
      return UserName;
  }
  
  public void setUserName(String userName) {
      UserName = userName;
  }
  
  public String getPassword() {
      return Password;
  }
  
  public void setPassword(String password) {
      Password = password;
  }
  
  public Role getUserRole() {
      return userRole;
  }
  
  public void setUserRole(Role userRole) {
      this.userRole = userRole;
  }
  
  }
  </code></pre>
  
  <p><strong>User jsp page</strong></p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%&gt;
  &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%&gt;   
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;title&gt;Registration&lt;/title&gt;
  &lt;style&gt;
      .error {
          color: red; font-weight: bold;
      }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div align="center"&gt;
          &lt;form:form action="addUser" method="post" modelAttribute="userFrom"&gt;
              &lt;table border="0"&gt;
                  &lt;tr&gt;
                      &lt;td colspan="2" align="center"&gt;&lt;h2&gt;Spring MVC Form Demo - Registration&lt;/h2&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                 &lt;tr&gt;
                      &lt;td&gt;User Name:&lt;/td&gt;
                      &lt;td&gt;&lt;form:input path="UserName" /&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;form:errors path="UserName" cssClass="error" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;td&gt;Password:&lt;/td&gt;
                      &lt;td&gt;&lt;form:password path="Password" /&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;form:errors path="Password" cssClass="error" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Mobile No:&lt;/td&gt;
                      &lt;td&gt;&lt;form:input path="MobileNo" /&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;form:errors path="MobileNo" cssClass="error" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;td colspan="2" align="center"&gt;&lt;input type="submit" value="Register" /&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/form:form&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>And finnaly controller class. where i'm trying to run simple Sign up operation, and validation for field value.</strong></p>
  
  <pre><code>package com.kalam.controller;
  
  import javax.validation.Valid;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  import com.kalam.daoimpl.EmployeeDaoImpl;
  import com.kalam.model.Employee;
  import com.kalam.model.User;
  import com.kalam.service.EmployeeService;
  import com.kalam.serviceimpl.EmployeeServiceImpl;
  
  
  
  
  @Controller
  
  public class KalamController {
  
  //@Autowired 
  //EmployeeService employeeService;
  
      @RequestMapping("/kalam")
      public String showMessage(ModelMap map) {
  
          map.put("dollar", "50 US $");
          return "KalamWorld";
      }
  
      @RequestMapping("/insertData")
      public void InserData() {
  
          Employee emp= new Employee();
          emp.setEmpID(11);
          emp.setEmpName("On Target");
          emp.setEmpSalary(20000);
          emp.setAddress("Mumbai");
  
  
              ApplicationContext context=new ClassPathXmlApplicationContext("hibernate-cfg.xml"); 
              EmployeeDaoImpl dao= (EmployeeDaoImpl)context.getBean("employeeDaoImpl");
              dao.addEmployee(emp); 
              System.out.println("Data successfully inserted");
  
      //  employeeService.addEmployee(emp);  
      } 
  
  
      @RequestMapping(value ="/",method = RequestMethod.GET)
      public String login(ModelMap model) {
          User userForm=new User();
          model.put("userFrom", userForm);
          return "User";
  
      }
  
      @RequestMapping(value = "/addUser", method = RequestMethod.POST)
         public String addEmployee(@Valid @ModelAttribute("userFrom")User user,BindingResult result) {
           if(result.hasErrors()){
               return "User";
           }
  
            return "success";
         }
  
  
      @RequestMapping(value ="/welcome",method = RequestMethod.GET)
      public String welcome(ModelMap model) {
          return "User";
  
      }
  
  
  
  }
  </code></pre>
  
  <p><strong>When i click on register button without filling any value, it is not showing me any error, instead it redirect to success page. Please help me. Thank you.</strong></p>