Next Previous Index

7. Map


Definition:

A map is a simple name-value pair list stored on a first rank collection.


Scenario:

First rank class Foo has a map containing people's ages indexed by their names


Map Foo.getAges()   //  returns a collection of String name-value pairs

Hibernate Mapping:

In Hibernate, this could be mapped as follows:


<class name="Foo" table="foo">
    ...
    <map role="ages">
        <key column="id"/>
        <index column="name" type="string"/>
        <element column="age" type="string"/>
    </map>
</class>

Table Schema:

Foo

id

Ages

id

name

age


A simple extra table, Ages, is used to store the name and age string-value pair. Note that the map needs its own identity column too: id.


Bidirectionality:

Bidirectionality has no meaning for a map.



Next Previous Index