Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.1.0) Part Number B28221-02 |
|
|
View PDF |
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.
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>