title: Mapping object with data from another table using foreign key with Hibernate
body: <p>I am trying to populate the data within this class from a database using Hibernate and javax persistence annotations.  Here are the relevant database structures. </p>
  
  <pre><code>table Poss_resp     
  ID  qst_id  resp_text
  int int text
  
  table Responses         
  ID  qst_id  usr_id  resp_id
  int int int int
  </code></pre>
  
  <p>I am trying to populate the Response class shown below with Responses.ID, and Poss_resp.resp_text.  Poss_resp holds possible answers to a question.  Responses holds the actual answers given.  resp_id is a foreign key for Poss_resp.  However, I just want the resp_text string stored, I do not want a whole new object.  Is there some way to achieve this?  I cannot figure out how to tell Hibernate how to use something other than Response's primary key, nor have I determined the proper JOIN syntax.</p>
  
  <p>My Response class:   </p>
  
  <pre><code>@Entity
  @Table(name="responses")
  public class Response {
  
      private long id;
      private long qst_id;
      private long resp_id;
      private String resp_text;
  
  
      /**
       * 
       */
      public Response() {
          // TODO Auto-generated constructor stub
      }
  
  
      /**
       * @return the id
       */
      @Id
      @Generated(value="assigned")
      @Column(name="ID")
      public long getId() {
          return id;
      }
  
  
      /**
       * @param id the id to set
       */
      public void setId(long id) {
          this.id = id;
      }
  
  
      /**
       * @return the qst_id
       */
      @Column(name="qst_id")
      public long getQst_id() {
          return qst_id;
      }
  
  
      /**
       * @param qst_id the qst_id to set
       */
      public void setQst_id(long qst_id) {
          this.qst_id = qst_id;
      }
  
  
      /**
       * @return the resp_id
       */
      @Column(name="resp_id")
      public long getResp_id() {
          return resp_id;
      }
  
  
      /**
       * @param resp_id the resp_id to set
       */
      public void setResp_id(long resp_id) {
          this.resp_id = resp_id;
      }
  
  
      /**
       * @return the resp_text
       */
      public String getResp_text() {
          return resp_text;
      }
  
  
      /**
       * @param resp_text the resp_text to set
       */
      public void setResp_text(String resp_text) {
          this.resp_text = resp_text;
      }
  </code></pre>
  
  <p>If at all possible, I would prefer annotations.</p>