title: java.sql.SQLException: No value specified for parameter
body: <p>I am getting following error while using Spring MVC with hibernate Annotations. I am trying to insert the record in the database using <code>AUTO_INCREMENT</code> on the mysql database table Employee. On the model class I have the entry as below -</p>
  
  <pre><code>@Entity
  @Table(name="EMPLOYEES")
  public class Employee implements Serializable{
  
  private static final long serialVersionUID = -1798070786993154676L;
  
  @Id
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  @Column(name="emp_no")
  private int empNo=0;
  
  @Column(name="birth_date")
  private Date birthDate;
  
  @Column(name="first_name")
  private String firstName;
  
  @Column(name="last_name")
  private String lastName;
  
  @Column(name="gender")
  @Enumerated(EnumType.STRING)
  private Gender gender=Gender.M;
  
  @Column(name="hire_date")
  private Date hireDate;
  
  public Employee() {
      // TODO Auto-generated constructor stub
  }
  
  public int getEmpNo() {
      return empNo;
  }
  
  public void setEmpNo(int empNo) {
      this.empNo = empNo;
  }
  
  public Date getBirthDate() {
      return birthDate;
  }
  
  public void setBirthDate(Date birthDate) {
      this.birthDate = birthDate;
  }
  
  public String getFirstName() {
      return firstName;
  }
  
  public void setFirstName(String firstName) {
      this.firstName = firstName;
  }
  
  public String getLastName() {
      return lastName;
  }
  
  public void setLastName(String lastName) {
      this.lastName = lastName;
  }
  
  public Gender getGender() {
      return gender;
  }
  
  public void setGender(Gender gender) {
      this.gender = gender;
  }
  
  public Date getHireDate() {
      return hireDate;
  }
  
  public void setHireDate(Date hireDate) {
      this.hireDate = hireDate;
  }
  
  public String toString(){
      return "EmpNo ::::"+this.empNo+"Birth Date ::::"+this.birthDate
              +"First Name ::::"+this.firstName+" Last Name::::"+
              this.lastName+" Hire Date ::::"+this.hireDate+" Gender::::"+this.gender;
  }
  }
  </code></pre>
  
  <p>On Database side I have defined the primary type column as below :</p>
  
  <pre><code>Field       Type            Null  Key   Extra 
  emp_no      int(11)         NO    PRI   auto_increment
  birth_date  date            YES         
  first_name  varchar(14)     YES         
  last_name   varchar(16)     YES         
  GENDER      enum('M','F')   YES         
  hire_date   date            YES         
  </code></pre>
  
  <p>addEmployee method as follows :</p>
  
  <pre><code>@RequestMapping(value="/save",method=RequestMethod.POST)
  public ModelAndView saveEmployee(@ModelAttribute("command")EmployeeBean employeeBean,BindingResult bindingResult){
      Employee employee=prepareModel(employeeBean);
      employeeService.addEmployee(employee);
      Map&lt;String, Object&gt; model=new HashMap&lt;String,Object&gt;();
      model.put("employees", prepareListOfEmployeeBeans(employeeService.listEmployees()));
      model.put("genders", employeeBean.getGender().values());
      return new ModelAndView("redirect:/add.html");
  }
  
  public Employee prepareModel(EmployeeBean employeeBean)
  {
      if(employeeBean!=null){
          Employee employee=new Employee();
          employee.setFirstName(employeeBean.getFirstName());
          employee.setLastName(employeeBean.getLastName());
          employee.setGender(employeeBean.getGender());
          employee.setHireDate(employeeBean.getHireDate());
  //          employee.setEmpNo(employeeBean.getEmpNo());
          employee.setBirthDate(employeeBean.getBirthDate());
  //          employeeBean.setEmpNo(null);
          return employee;
      }
      return null;
  }
  </code></pre>
  
  <p>AddEmployee JSP :</p>
  
  <pre><code>&lt;%@page import="org.springframework.web.servlet.ModelAndView"%&gt;
  &lt;%@page import="java.util.Map"%&gt;
  &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%&gt;
  &lt;%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;  
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&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=ISO-8859-1"&gt;
  &lt;title&gt;Add Employee Form&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form:form modelAttribute="command" action="/MVC_CRUD_SPRING/save.html" method="post"&gt;
      &lt;table&gt;
          &lt;tr&gt;
          &lt;td colspan="2" align="center"&gt;&lt;b&gt;Add Employee Form&lt;/b&gt;&lt;/td&gt;    
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="empNo"&gt;Employee Number&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="empNo" value="${employee.empNo}" readonly="true"/&gt; &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="birthDate"&gt;Birth Date&lt;/form:label&gt; &lt;/td&gt;
          &lt;td&gt;&lt;form:input path="birthDate" value="${employee.birthDate}"/&gt; &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="firstName"&gt;First Name&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="firstName" value="${employee.firstName}"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="lastName"&gt;Last Name&lt;/form:label&gt; &lt;/td&gt;
          &lt;td&gt;&lt;form:input path="lastName" value="${employee.lastName}"/&gt; &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="Gender"&gt;Gender&lt;/form:label&gt;&lt;/td&gt;
  &lt;%--            &lt;td&gt;&lt;form:radiobutton path="gender" value="M"/&gt;Male &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;form:radiobutton path="gender" value="F"/&gt;Female&lt;/td&gt; -  -%&gt;
          &lt;td&gt;&lt;form:radiobuttons path="gender" items="${genders}"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="hireDate"&gt;Hire Date&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="hireDate" value="${employee.hireDate}"/&gt; &lt;/td&gt;            
          &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td colspan="2"&gt;
          &lt;input type="submit" value="Submit"/&gt;
          &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form:form&gt; 
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The error stack trace :</p>
  
  <pre><code>Hibernate: insert into EMPLOYEES (birth_date, first_name, last_name, gender, hire_date, emp_no) values (?, ?, ?, ?, ?, ?)
  Apr 20, 2015 3:22:57 PM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet [employee] in context with path [/MVC_CRUD_SPRING] threw exception [Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not insert: [com.cybage.projects.model.Employee]] with root cause
  java.sql.SQLException: No value specified for parameter 6
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
  at  com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2578)
  </code></pre>
  
  <p>In the above code snippet while creating model of Employee I have commented out <code>employee.setEmpNo</code> method in <code>prepareModel</code>. What I think is as Employees table emp_no field has auto-increment I don't need to explicitly set <code>empNo</code> value, the database should take care of this. If I am uncommenting this , then also it is not working.</p>
  
  <p>Any body who can help me understanding where </p>