Oracle GlassFish Server 3.0.1 Application Development Guide

Relationship Prefetching

In many cases when an entity bean’s state is fetched from the database, its relationship fields are always accessed in the same transaction. Relationship prefetching saves database round trips by fetching data for an entity bean and those beans referenced by its CMR fields in a single database round trip.

To enable relationship prefetching for a CMR field, use the default subelement of the fetched-with element in the sun-cmp-mappings.xml file. By default, these CMR fields are prefetched whenever findByPrimaryKey or a custom finder is executed for the entity, or when the entity is navigated to from a relationship. (Recursive prefetching is not supported, because it does not usually enhance performance.) See fetched-with in Oracle GlassFish Server 3.0.1 Application Deployment Guide.

To disable prefetching for specific custom finders, use the prefetch-disabled element in the sun-ejb-jar.xml file. See prefetch-disabled in Oracle GlassFish Server 3.0.1 Application Deployment Guide.

Multilevel relationship prefetching is supported for CMP 2.1 entity beans. To enable multilevel relationship prefetching, set the following property using the asadmin create-jvm-options command:

asadmin create-jvm-options