title: Difference between @MapKey, @MapKeyColumn and @MapKeyJoinColumn in JPA and Hibernate
body: <p>As per <a href="http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch07.html">Hibernate documentation</a>, there are multiple annotations available if we want to use Map as an association between our entities. The doc says:</p>
  
  <blockquote>
    <p>Alternatively the map key is mapped to a dedicated column or columns.
    In order to customize the mapping use one of the following
    annotations:</p>
    
    <p>@MapKeyColumn if the map key is a basic type. If you don't specify the
    column name, the name of the property followed by underscore followed
    by KEY is used (for example orders_KEY). @MapKeyEnumerated /
    @MapKeyTemporal if the map key type is respectively an enum or a Date.
    @MapKeyJoinColumn/@MapKeyJoinColumns if the map key type is another
    entity. @AttributeOverride/@AttributeOverrides when the map key is a
    embeddable object. Use key. as a prefix for your embeddable object
    property names. You can also use @MapKeyClass to define the type of
    the key if you don't use generics.</p>
  </blockquote>
  
  <p>By doing some examples I am able to understand that @MapKey is just used to map the key to a property of target entity and this key is used only for fetching records. @MapKeyColumn is used to map the key to a property of target entity and this key is used to save as well as fetching records. Please let me know if this is correct?</p>
  
  <p>Also please let me know when I need to use @MapKeyJoinColumn/@MapKeyJoinColumns &amp; @MapKeyEnumerated / @MapKeyTemporal</p>
  
  <p>Thanks!</p>