Next Previous Index

14. Composite Index


Definition:

A Composite Index is used to provide a multi-column Map key. The semantics are very similar to Composite Id.


Scenario:

Foo contains a map of ages (strings). The map is keyed by Person, where Person is mapped as a String column (name) and Address instance.


Map Foo.getAges()   // Foo contains a map of ages, keyed by Person

Hibernate Mapping:

In Hibernate, this could be mapped as follows:


<class name="Foo" table="foo">
    ...
    <map role="ages">
        <key column="id"/>
        <composite-index class="Person">
            <key-property name="name" type="string" column="name"/>
            <key-many-to-one name="address" class="Address" column="addr_id"/>
        </composite-index>
        <element column="age" type="string"/>
    </map>
</class>

<class name="Address" table="address">
    ...
</class>

Table Schema:

Foo

id

Ages

id

name

addr_id

age

Address

id


Here the table Ages is created to hold the map. The key is made up of the columns name and addr_id which are used to map Person keys. The age field holds the map value. Finally, the map table needs its own id which is stored in the id field.


Bidirectionality:

Bidirectionality has no meaning here.



Next Previous Index