[ Team LiB ] Previous Section Next Section

Relationship Caching in EJBs

Caching of Entity beans and their related Entity beans improves performance by reducing the number of JOIN queries that have to be executed. In our earlier example, we had three types of relationships:

  • One-to-one— A doctor has an assistant.

  • One-to-many— A doctor has multiple patients.

  • Many-to-many— A doctor works at multiple hospitals and each hospital has multiple doctors.

The <relationship-caching> tag of weblogic-cmp-rdbms.xml is used to specify caching of these relationships. Listing 22.17 is an excerpt from a weblogic-cmp-rdbms.xml file showing the caching of relationships.

Listing 22.17 weblogic-cmp-rdbms Excerpt
<relationship-caching>
        <caching-name>cacheMoreBeans</caching-name>
        <caching-element>
                <cmr-field>assistantName</cmr-field>
                <group-name>assistants</group-name>
        </caching-element>
        <caching-element
                <cmr-field>patientName</cmr-field>
                <group-name>patients</group-name>
        </caching-element>
        <caching-element>
               <cmr-field>hospitalName</cmr-field>
         <group-name>hospitals</group-name>
        </caching-element>
</relationship-caching>

It's important to note that relationship caching is not supported for many-to-many relationships. This is obviously because it can lead to deadlocks.

    [ Team LiB ] Previous Section Next Section