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:
|
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:
serialized
: Will use a SerializedObjectConverter
on the associated mapping. When using a SerializedObjectConverter
the database representation is a binary field holding a serialized version of the object and the object-model representation is a the actual object
class-instance
: Will use an ClassInstanceConverter on the associated mapping. When using a ClassInstanceConverter the database representation is a String representing the Class name and the object-model representation is an instance of that class built with a no-args constructor
none
- Will place no converter on the associated mapping. This can be used to override a situation where either another converter is defaulted or another converter is set.
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: