title: How to match a hibernate/JPA table without a foreign key
body: <p>I would like to map a property (virtually) into the Entity linking to another entity that has no foreign key and without changing the database structure. There is already a getter for the key that maps to the related table.</p>
  
  <p>An existing database.</p>
  
  <p>Table egg</p>
  
  <pre><code>+----------------------+------------------+------+-----+---------+-------+
  | Field                | Type             | Null | Key | Default | Extra |
  +----------------------+------------------+------+-----+---------+-------+
  | id                   | int(10) unsigned | NO   | PRI | 0       |       |
  | pid                  | varchar(60)      | NO   |     |         |       |
  </code></pre>
  
  <p>Table basket</p>
  
  <pre><code>+----------------------+------------------+------+-----+---------+-------+
   | Field                | Type             | Null | Key | Default | Extra |
  +----------------------+------------------+------+-----+---------+-------+
  | id                   | int(10) unsigned | NO   | PRI | 0       |       |
  | pid                  | varchar(60)      | NO   |     |         |       |
  </code></pre>
  
  <p>The Entity Egg</p>
  
  <pre><code>@SuppressWarnings("serial")
  @Entity
  @Table(name = "egg")
  public class Egg implements java.io.Serializable {
    private long id;
    private String pid;
    ...
    @Column(name = "pid")
     public String getPid() {
      return this.pid;
     }
  </code></pre>
  
  <p>The Entity for basket is similar with the pid getter already set as for egg.</p>
  
  <p>I would like to model a join.</p>
  
  <pre><code>LEFT JOIN egg ON basket.pid = egg.pid
  </code></pre>
  
  <p>There is no foreign key on either table mapping pid together. </p>
  
  <p>I have tried creating a basket property in the egg entity. </p>
  
  <p>e.g. </p>
  
  <pre><code>@JoinColumn(name = "pid", referencedColumnName = "pid", updatable = false, insertable = false)
  public Basket getBasket(
  </code></pre>
  
  <p>Of course hibernate complains that there is no 'basket' column in the table.</p>
  
  <p>How do I get a the basket for this egg?</p>