Next Previous Index

8. Entity Map


Definition:

An entity map is a map who is keyed by an entity class (i.e. First-rank) rather than a simple property.


Scenario:

Foo holds a Map of people's ages. This map is keyed by the Name entity class. Name holds a person's name as a string property.


Map Foo.getAges()     //  returns a collection of Person-String instances

Hibernate Mapping:

In Hibernate, this could be mapped as follows:


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

<class name="Person" table="person">
    ...
    <property name="name" column="name" type="string"/>
</class>

Table Schema:

Foo

id

Person

id

name

Ages

id

person_id

age


As for the normal map a simple extra table, Ages, is used to store the Person FK and age data.


Bidirectionality:

Bidirectionality has no meaning for an entity map.



Next Previous Index