title: How do I fix error: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long';
body: <p>I'm working on a project manager -web app that allows you to sign in as a member and join different kinds of projects. Members can take part in multiple projects. Project and Member -Entities are connected by a Membership -Entity. Every time a logged in member joins a project a new membership Entity is created.</p>
  
  <p>However I'm having trouble creating a new membership after member clicks Join-button on joinProject.html -page. I keep getting following error message:</p>
  
  <pre><code>(type=Bad Request, status=400).
  Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "saveMembership"
  </code></pre>
  
  <p>The goal is to add logged in member to a project. The new membership can be seen listed on projectDetails.html -page.</p>
  
  <p>I'm using Spring Boot, Thymeleaf and JPA. I have a feeling this is something really simple and stupid but I just can't find the problem. :(</p>
  
  <p>If you need to see more code or information I will be happy to provide.</p>
  
  <p>Thank you for your time!</p>
  
  <p>Here is the MembershipCreatorObject-class that I try to use to get the needed data into my controller:</p>
  
  <pre><code>public class MembershipCreatorObject {
  
      private String id;
      private String username;
      private String jobDescription;
  
      public MembershipCreatorObject() {
          super();
      }
  
      public MembershipCreatorObject(String id, String username, String jobDescription) {
          super();
          this.id = id;
          this.username = username;
          this.jobDescription = jobDescription;
      }
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public String getUsername() {
          return username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public String getJobDescription() {
          return jobDescription;
      }
  
      public void setJobDescription(String jobDescription) {
          this.jobDescription = jobDescription;
      }
  </code></pre>
  
  <p>Here is my controller:</p>
  
  <pre><code>
      @RequestMapping(value= {"/joinProject/{projectId}"})
      public String joinProject(@PathVariable("projectId") Long urlId, Model model) {
  
          model.addAttribute("mObject", new MembershipCreatorObject());
  
          model.addAttribute("project", projectRepo.findByProjectId(urlId));
  
          return "joinProject";
      }
  
      @RequestMapping(value="/saveMembership", method=RequestMethod.POST)
      public String saveMembership(MembershipCreatorObject mObject) {
  
          String id = mObject.getId();
  
          Long idConverted = Long.parseLong(id);
  
          String username = mObject.getUsername();
  
          String description = mObject.getJobDescription();
  
          Project projectToAdd = projectRepo.findByProjectId(idConverted);
  
          Member memberToAdd = memberRepo.findByUsername(username);
  
          Membership membershipToAdd = new Membership(description, memberToAdd, projectToAdd);
  
          membershipRepo.save(membershipToAdd);
  
          return "redirect:/projectCatalog";
      }
  </code></pre>
  
  <p>Here is the joinProject -html file.</p>
  
  <pre><code>    &lt;h1&gt;Join Project&lt;/h1&gt;
  
      &lt;h4 th:inline="text"&gt;Logged in as: [[${#httpServletRequest.remoteUser}]]&lt;/h4&gt;
  
      &lt;form th:object="${mObject}" th:action="@{saveMembership}" action="#" style="padding: 20px;" method="POST"&gt;
  
          &lt;input th:field="*{id}" /&gt;
          &lt;!-- th:value="${project.projectId}" --&gt;
  
          &lt;input type="text" th:field="*{username}" /&gt;
          &lt;!-- th:value="${#httpServletRequest.remoteUser}" --&gt;
  
          &lt;label&gt;What will you be working on?&lt;/label&gt;
          &lt;input type="text" th:field="*{jobDescription}" style="display: block;" /&gt;
  
          &lt;input type="submit" value="Join" style="display: block; margin-top:10px; width:70px;"&gt;
  
      &lt;/form&gt;
  </code></pre>