Failed To Convert Property Value Of Type Java.lang.String To Required Type Long For Property Phone; Nested Exce

- 1 answer

I am trying to built my first Spring mvc application And working on Spring Mvc Form Validation.I am trying to check for empty field. But when to validate the 'long' type variable with @NotNull annotation it give me the above error.

I don't know how to solve it.

Here is My Student Bean

public class Student {
private String name;
@Size(min=2, max=10) 
private String father;

private String cnic; 
private String email;

private long phone;

public long getPhone() {
    return phone;

public void setPhone(long phone) { = phone;

public String getName() {
    return name;

public void setName(String name) { = name;

public String getCnic() {
    return cnic;

public void setCnic(String cnic) {
    this.cnic = cnic;

public String getFather() {
    return father;

public void setFather(String father) {
    this.father = father;

public String getEmail() {
    return email;

public void setEmail(String email) { = email;


And my file should not contain any Digits 
        Size.student1.father=please give the {0} between {2} and {1} characters the email are requried provide integer data

Controller Class

public class StudentController {

    public String std(Model m){
        m.addAttribute("message", "Welcome To Registration ");
        return "studentreg";

    public ModelAndView insert(@Valid @ModelAttribute("student1") Student student1,BindingResult result)   //ModelAttribute is used to directly connect the form data to the bean class

    ModelAndView model=new ModelAndView("studentreg");

    return model;
    ModelAndView mo=new ModelAndView("success");
    mo.addObject("message","user detail");
    mo.addObject("stu", student1);
    return mo;

Jsp file is

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@taglib uri="" prefix="form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<h2 align="center">${ message}</h2>

<form:errors path="" style="color:red"/><br>
<form:form name="form" method="post" action="stu" >
<div align="center">
${ error}
     <td>Name :</td><td><input type="text" name="name" placeholder="EnterName"></td>
                    <td>Father Name</td>
                    <td><input type="text" name="father" placeholder="EnterFatherName"/></td>
                    <td><input type="text" name="cnic" placeholder="Enter CNIC"/></td>
                    <td><input type="text" name="email" placeholder="Enter Email"/></td>
                    <td><input type="text" name="phone" placeholder="Enter Phone"/></td>
                  <form:errors path="phone"/>


                    <td><input type="submit" name="submite" value="Send"/></td>



Try to use Long instead of long.

Because long can never be null it is not primitive type.

So you should use Long.