Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.5
  Go To Table Of Contents
 Search
 PDFComments
Comments


@MapKeyConvert

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

value

(Optional) Name of the converter to use:

  • serialized

  • class-instance

  • none

  • custom converter

none



Usage

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.


Examples

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

Example 2-56 Using @MapKeyConvert Annotation

@Entity
public class Entity
 …
    @ElementCollection
    @MapKeyColumn(name=”BANK”)
    @Column(name=”ACCOUNT”)
    @Convert(“Long2String”)
    @MapKeyConvert(“CreditLine”)
    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-convert>CreditLine</map-key-convert>
  <map-key-column name="BANK"/>
  <column name="ACCOUNT"/>
  <convert>Long2String</convert>
  <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"/>
  </object-type-converter>
  <type-converter name="Long2String" data-type="String" object-type="Long"/>
  <collection-table name="EMP_CREDITLINES">
    <join-column name="EMP_ID"/>
  </collection-table>
</element-collection>


See Also

For more information, see: