title: Defining multiple Address properties in Person per AddressType by a triple join table
body: <p>I've here a database with a <code>PERSON</code> - <code>ADDRESS</code> - <code>ADDRESS_TYPE</code> relationship maintained by a triple join table <code>PERSON_ADDRESS</code>. The <code>PERSON</code>-<code>ADDRESS</code> relationship is effectively one-to-many.</p>
  
  <p><code>PERSON</code></p>
  
  <pre>
  ID FIRSTNAME LASTNAME
  -- --------- --------
  1  John      Doe
  2  Jane      Doe
  </pre>
  
  <p><code>ADDRESS</code></p>
  
  <pre>
  ID STREET               CITY
  -- -------------------- -------------
  1  Home Street 1        Hometown
  2  Office Street 1      Officetown
  3  Main Street 1        Maintown
  4  Business Building 1  Businesstown
  </pre>
  
  <p><code>ADDRESS_TYPE</code></p>
  
  <pre>
  ID NAME
  -- ---------------
  1  Home Address
  2  Office Address
  </pre>
  
  <p><code>PERSON_ADDRESS</code></p>
  
  <pre>
  PERSON_ID ADDRESS_TYPE_ID ADDRESS_ID
  --------- --------------- ----------
  1         1               1
  1         2               2
  2         1               3
  2         2               4
  </pre>
  
  <p>For practical reasons, I'd like to have my <code>Person</code> entity to end up like:</p>
  
  <pre><code>public class Person {
      private Address homeAddress; // Insertable/updateable by ADDRESS_TYPE_ID=1
      private Address officeAddress; // Insertable/updateable by ADDRESS_TYPE_ID=2
  }
  </code></pre>
  
  <p>Is this ever possible with JPA 2.0 annotations?</p>
  
  <p>I've read the <a href="http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Map_Key_Columns_.28JPA_2.0.29" rel="nofollow noreferrer">Map Key Columns chapter of the JPA wikibook</a> and it seems that I have to use a <a href="http://download.oracle.com/javaee/6/api/javax/persistence/MapKeyJoinColumn.html" rel="nofollow noreferrer"><code>@MapKeyJoinColumn</code></a>, but it's not entirely clear to me how to successfully use it in this situation. I expected to see a <code>@JoinColumn</code> example along it, but it is absent in the code snippets in the wikibook.</p>
  
  <p>If that's not possible with <code>@MapKeyJoinColumn</code>, then an alternative approach with help of maybe <a href="http://download.oracle.com/javaee/6/api/javax/persistence/MapKeyClass.html" rel="nofollow noreferrer"><code>@MapKeyClass</code></a> on a <code>Map&lt;AddressType, Address&gt;</code> is also welcome, as long as I can end up with a <code>getHomeAddress()</code> and <code>getOfficeAddress()</code> in the <code>Person</code> entity. </p>