title: Error: java.lang.NoSuchMethodException: java.lang.Long.<init>() in spring MVC
body: <p>I am getting this error while reading a <em>student</em> object from database.</p>
  <pre><code>org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.Long]: No default constructor found; nested exception is java.lang.NoSuchMethodException: java.lang.Long.&lt;init&gt;()
  org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:107)
  </code></pre>
  <h3>Full stack trace:</h3>
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.Long]: No default constructor found; nested exception is java.lang.NoSuchMethodException: java.lang.Long.&lt;init&gt;()
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  root cause
  
  org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.Long]: No default constructor found; nested exception is java.lang.NoSuchMethodException: java.lang.Long.&lt;init&gt;()
      org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:107)
      org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveModelAttribute(HandlerMethodInvoker.java:775)
      org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:368)
      org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:172)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  root cause
  
  java.lang.NoSuchMethodException: java.lang.Long.&lt;init&gt;()
      java.lang.Class.getConstructor0(Class.java:3082)
      java.lang.Class.getDeclaredConstructor(Class.java:2178)
      org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
      org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveModelAttribute(HandlerMethodInvoker.java:775)
      org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:368)
      org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:172)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  </code></pre>
  <h3>File <em>Student.java</em></h3>
  <pre><code>@Entity
  @Table(name=&quot;Student&quot;)
  public class Student implements Serializable{
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      @Column(name=&quot;studentId&quot;)
      Long studentId;
  
      @Column(name=&quot;studentName&quot;)
      String studentName;
  </code></pre>
  <h3>File <em>Controller.java</em></h3>
  <pre><code>    @RequestMapping(value = &quot;/read.html&quot;)
      public String readStudent(Model model, @ModelAttribute(&quot;studentId&quot;) Long studentId) {
          Student student = null;
          studentId = 2l;
          try{
              student = serviceFile.readStudent(studentId);
          }catch(Exception e){
              model.addAttribute(&quot;message&quot;, &quot;Some thing went wrong !!!! Exception occoured&quot;);
              return &quot;message&quot;;
          }
          model.addAttribute(&quot;student&quot;, student);
          return &quot;read&quot;;
      }
  </code></pre>
  <h3>File <em>daoImpl.java</em></h3>
  <pre><code>@Repository
  @Transactional
  public class DaoImplFile implements DaoFile {
  
      private EntityManager entityManager;
  
      public EntityManager getEntityManager() {
          return entityManager;
      }
  
      @PersistenceContext
      public void setEntityManager(EntityManager entityManager) {
          this.entityManager = entityManager;
      }
  
      @Override
      public Student read(Long studentId) throws NullPointerException {
          Student student = entityManager.find(Student.class, studentId);
          if (student!=null) {
              return student;
          } else {
              return null;
          }
      }
  </code></pre>