title: Composite Primary Key usage in REST Spring Boot
body: <p>I never saw this form helpful to me. I wish it will be now.</p>
  
  <p>In my spring-boot, My database has two primary keys </p>
  
  <blockquote>
    <p>TransId  and PrsnRef</p>
  </blockquote>
  
  <p>Now When I create Entity's for my database Table named PersonCore I am getting 2 classes</p>
  
  <blockquote>
    <p>PersonCore (As known this has all rest of data)</p>
  </blockquote>
  
  <pre><code>/**
   * The persistent class for the PERSON_CORE database table.
   * 
   */
  @Entity
  @Table(name="PERSON_CORE")
  @NamedQuery(name="PersonCore.findAll", query="SELECT f FROM PersonCore f")
  public class PersonCore implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @EmbeddedId
      private PersonCorePK id;
  
      @Column(name="PRSN_AGE")
      private BigDecimal prsnAge;
  
      @Column(name="PRSN_AMER_INDIAN_ALASKA_NTV")
      private String prsnAmerIndianAlaskaNtv;
  
      @Column(name="PRSN_DOB")
      private String prsnDob;
  </code></pre>
  
  <blockquote>
    <p>PersonCorePK (This has two Id's transid and personref)</p>
  </blockquote>
  
  <pre><code>    /**
   * The primary key class for the PERSON_CORE database table.
   * 
   */
  @Embeddable
  public class PersonCorePK implements Serializable {
      //default serial version id, required for serializable classes.
      private static final long serialVersionUID = 1L;
  
      @Column(name="TRANS_ID")
      private String transId;
  
      @Column(name="PRSN_REF")
      private String prsnRef;
  
      public FdshPersonCorePK() {
      }
      public String getTransId() {
          return this.transId;
      }
      public void setTransId(String transId) {
          this.transId = transId;
      }
      public String getPrsnRef() {
          return this.prsnRef;
      }
      public void setPrsnRef(String prsnRef) {
          this.prsnRef = prsnRef;
      }
  </code></pre>
  
  <p>I am trying to create a RESTFul service using spring-boot 
  I created repository with @RepositoryRestResource(bla bla bla)</p>
  
  <pre><code>@RepositoryRestResource(path = "person", collectionResourceRel = "FdshPersonHDR")
  public interface PersonCoreRepository extends PagingAndSortingRepository&lt;PersonCore, PersonCorePK&gt; {
      Collection&lt;PersonCore &gt; findAll();
      Collection&lt;PersonCore &gt; findAllByIdTransIdAndIdPrsnRef(@Param("transid")String transId, @Param("prsnRef") String prsnRef);
  }
  </code></pre>
  
  <p>Spring boot is so awesome that it takes good care of me.
  Lets see ...</p>
  
  <p>When I try to fetch all records from database its all fine except the final link is something like this</p>
  
  <blockquote>
    <p><a href="http://localhost:8080/person/com.----.Application.Methods.PersonCorePK@83e14116" rel="nofollow">http://localhost:8080/person/com.----.Application.Methods.PersonCorePK@83e14116</a></p>
  </blockquote>
  
  <p>This is driving me crazy. I know its reading what I want but not displaying me exactly what I need.  I want help figuring out how I can convert that "com.----.Application.Methods.PersonCorePK@83e14116" . It should actually display transid of that record.</p>
  
  <p>And please let me know if there is anyway we can add those two composite keys to that o/p format because I am getting all data I want except those two which are kind of important for me. I am not sure I can use two @Id's in single Entity. But I will check into it.</p>
  
  <p><a href="http://i.stack.imgur.com/0IGVb.png" rel="nofollow">Sample Screenshot</a></p>