Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (10.1.3.5.0)

Part Number E13981-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Configuring Lazy Loading on Finder Methods

Each finder method retrieves one or more objects. In the default scenario (which is set to NO lazy loading), the finder method causes a single SQL select statement to be executed against the database. For an entity bean with container-managed persistence, one or more objects are retrieved with all of their container-managed persistent fields. So, for example, with the findAllEmployees method, this finder retrieves all employee objects with all of the container-managed persistent fields in each employee object.

If you turn on lazy loading, then only the primary keys of the objects retrieved within the finder are returned. Then, only when you access the object within your implementation, OC4J uploads the actual object based on the primary key. With the findAllEmployees finder method example, all of the employee primary keys are returned in a Collection. The first time you access one of the employees in the Collection, OC4J uses the primary key to retrieve the single employee object from the database. You may want to turn on the lazy loading feature if the number of objects that you are retrieving is so large that loading them all into your local cache would be a performance degradation.

You have a performance consideration with lazy loading. If you retrieve multiple objects, but you only use a few of them, then you should turn on lazy loading. In addition, if you only use objects through the getPrimaryKey method, then you should also turn on lazy loading.

Using Deployment XML

To turn on lazy loading in the findByPrimaryKey method, set the findByPrimaryKey-lazy-loading attribute to true, as follows:

<entity-deployment ... findByPrimaryKey-lazy-loading="true" ... >

To turn on lazy loading in any custom finder method, set the lazy-loading attribute to true in the <finder-method> element for that custom finder, as follows:

<finder-method ... lazy-loading="true" ...>
  ...
</finder-method>