title: Spring Boot JPA RESTful No converter found capable of converting from type [java.lang.String] to type composite key
body: <p>I'm trying to connect my spring boot application to my mysql database. Everything seemed okay until I tried to map an entity with an embeddedId to another entity with another embeddedId. </p>
  
  <p>In my case here, I have a request table and a pledge table. A request can have many pledges.</p>
  
  <p>Request(pid, sttime, extime, endtime, minfund, maxfund, status)</p>
  
  <p>Request id has pid, sttime as composite key.</p>
  
  <p>Pledge(pid, sttime, extime, endtime, minfund, maxfund, status)</p>
  
  <p>Pledge id has four keys, pid, sttime, uemail, and pledgetime, where both pid and sttime references to request.</p>
  
  <pre><code>import javax.persistence.*;
  import java.util.Collection;
  import java.util.Date;
  
  @Entity
  public class Request {
  
      @EmbeddedId
      private RequestId requestId;
  
      @Temporal(TemporalType.TIMESTAMP)
      private Date extime;
      @Temporal(TemporalType.TIMESTAMP)
      private Date endtime;
      private int minfund;
      private int maxfund;
      @Enumerated(EnumType.STRING)
      @Column(name = "status")
      private RequestStatus status;
  
      @OneToMany(mappedBy = "pledgeId.request")
      private Collection&lt;Pledge&gt; pledges;
  
      protected Request(){}
  
      public Request(RequestId requestId, Date extime, Date endtime, int minfund, int maxfund, RequestStatus status) {
          this.requestId = requestId;
          this.extime = extime;
          this.endtime = endtime;
          this.minfund = minfund;
          this.maxfund = maxfund;
          this.status = status;
      }
      ...
      getters and setters
      ...
      @Override
      public String toString() {
          return String.format(
                  "Request[pid='%s', sttime='%s', extime='%s', endtime='%s', minfund='%s', maxfund='%s', status='%s']",
                  requestId.getProject().getPid(), requestId.getSttime(), extime, endtime, minfund, maxfund, status);
      }
  }
  </code></pre>
  
  <p>-</p>
  
  <pre><code>import javax.persistence.*;
  import java.io.Serializable;
  import java.io.UnsupportedEncodingException;
  import java.net.URLEncoder;
  import java.util.Date;
  
  @Embeddable
  public class RequestId implements Serializable {
  //    default serial version id, required for serializable classes.
      private static final long serialVersionUID = 1L;
  
      @ManyToOne
      @JoinColumn(name = "pid")
      private Project project;
  
      @Temporal(TemporalType.TIMESTAMP)
      private Date sttime;
  
      protected RequestId(){}
  
      public RequestId(Project project, Date sttime) {
          this.project = project;
          this.sttime = sttime;
      }
  
      public Project getProject() {
          return project;
      }
  
      public void setProject(Project project) {
          this.project = project;
      }
  
      public Date getSttime() {
          return sttime;
      }
  
      public void setSttime(Date sttime) {
          this.sttime = sttime;
      }
  
      @Override
      public boolean equals(Object o) {
          if (this == o) return true;
          if (o == null || getClass() != o.getClass()) return false;
  
          RequestId requestId = (RequestId) o;
  
          if (project != null ? !project.equals(requestId.project) : requestId.project != null) return false;
          return sttime != null ? sttime.equals(requestId.sttime) : requestId.sttime == null;
      }
  
      @Override
      public int hashCode() {
          int result = project != null ? project.hashCode() : 0;
          result = 31 * result + (sttime != null ? sttime.hashCode() : 0);
          return result;
      }
  
  //    @Override
  //    public String toString() {
  //        String timeUrl = "";
  //        try {
  //            timeUrl = URLEncoder.encode(sttime.toString(), "UTF-8");
  //        } catch (UnsupportedEncodingException e) {
  //            e.printStackTrace();
  //        }
  //
  //        String url = "";
  //        try {
  //            url = URLEncoder.encode("/search/findRequestByRequestIdProjectAndRequestIdSttime?pid="+project.getPid()+"&amp;sttime="+sttime, "UTF-8");
  //        } catch (UnsupportedEncodingException e) {
  //            e.printStackTrace();
  //        }
  //
  //        return "/search/findRequestByRequestIdProjectPidAndRequestIdSttime?pid="+project.getPid()+"&amp;sttime="+timeUrl;
  ////        return url;
  //    }
  
      @Override
      public String toString() {
          return "/RequestId{" +
                  "project=" + project.getPid() +
                  ", sttime=" + sttime.toString() +
                  '}';
      }
  }
  </code></pre>
  
  <p>-</p>
  
  <pre><code>import javax.persistence.*;
  
  @Entity
  public class Pledge {
  
      @EmbeddedId
      private PledgeId pledgeId;
      @ManyToOne
      @JoinColumn(name = "credit_card")
      private CreditCard credit_card;
      private int amount;
  
      ...
      constructors
      getter &amp; setters
      ...
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>import javax.persistence.*;
  import java.io.Serializable;
  import java.util.Date;
  
  @Embeddable
  public class PledgeId implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @MapsId("requestId")
      @ManyToOne
      @JoinColumns({
              @JoinColumn(name = "pid"),
              @JoinColumn(name = "sttime")
      })
      private Request request;
  
      @ManyToOne
      @JoinColumn(name = "uemail")
      private Customer customer;
  
      @Temporal(TemporalType.TIMESTAMP)
      private Date pledgetime;    
  
      ...
      constructors
      getter &amp; setters
      equals &amp; hashcode
      toString
      ...
  }
  </code></pre>
  
  <p>I failed to query every pledges from a certain request.
  For example,
  <a href="http://localhost:8080/requests/RequestId%7Bproject=1,%20sttime=2017-04-16%2012:00:00.0%7D/pledges" rel="nofollow noreferrer">http://localhost:8080/requests/RequestId%7Bproject=1,%20sttime=2017-04-16%2012:00:00.0%7D/pledges</a></p>
  
  <blockquote>
    <p>"No converter found capable of converting from type [java.lang.String] to type [crowdfunding.entity.RequestId]"</p>
  </blockquote>
  
  <p>Edited: I also tried to override toString() method so that it returns an API that can query itself when exposed, but didn't seem to be working as well.</p>