Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.4
  Go To Table Of Contents


Use @MapKeyConvert to specify a named converter to be used with the corresponding mapped attribute key column.

Annotation Elements

Table 2-31 describes this annotation's elements.

Table 2-31 @MapKeyConvert Annotation Elements

Annotation Element Description Default


(Optional) Name of the converter to use:

  • serialized

  • class-instance

  • none

  • custom converter



Use @MapKeyConvert to convert the key value used in a @MapKeyColumn to have a different type or value than the database column.

The @MapKeyConvert annotation has the following reserved names:

If you do not use one of these reserved names, you must define a custom converter, using the @Converter annotation.


Example 2-56 shows using a @MapKeyConvert annotation to apply a converter to a map's key.

Example 2-56 Using @MapKeyConvert Annotation

public class Entity
    public Map<String,Long> getCreditLines() {
        return creditLines;

Example 2-57 shows how to use the <map-key-convert> element in the eclipselink-orm.xml file.

Example 2-57 Using <map-key-convert> XML

<element-collection name="creditLines">
  <map-key-column name="BANK"/>
  <column name="ACCOUNT"/>
  <object-type-converter name="CreditLine">
    <conversion-value data-value="RBC" object-value="RoyalBank"/>
    <conversion-value data-value="CIBC" object-value="CanadianImperial"/>
    <conversion-value data-value="SB" object-value="Scotiabank"/>
    <conversion-value data-value="TD" object-value="TorontoDominion"/>
  <type-converter name="Long2String" data-type="String" object-type="Long"/>
  <collection-table name="EMP_CREDITLINES">
    <join-column name="EMP_ID"/>

See Also

For more information, see: