Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 594

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
ColdFusion ORM
<cfproperty name="artist" fieldtype="many-to-one" cfc="artist" fkcolumn="artistId"
lazy="true">
Important: An entity is loaded only once in the request (in Hibernate session) and there is always only one copy of it
in the request. So, for artwork and artist relationship, which is lazy, if the artist is already loaded, calling
will not create a proxy object and will return the loaded artist object.
art.getartist()
Lazy loading can be disabled by setting
Choosing an appropriate lazy loading option is very important for the performance of your application. Extra lazy
means more number of trips to the database (each trip to the database is expensive) but less data in memory whereas
no lazy loading means a huge object graph in the memory. So, you need to balance the approach based on the
application need.
Eager fetching
In this strategy, the associated object or collection is fetched together with the owning entity using a single SQL Join
query. This strategy reduces the number of trips to the database and is a good optimization technique when you always
access the associated object immediately after loading the owning entity. You can define this strategy by setting
for the relationship property definition in the CFC.
fetch="join"
Batch fetching
This strategy tells Hibernate to optimize the second SQL select in Immediate fetching or lazy fetching to load batch of
objects or collections in a single query. This allows you to load a batch of proxied objects or uninitilized collections
that are referenced in the current request. This is generally useful in nested tree loading. You can specify this using
attribute for CFC or relationship property.
"batchsize"
There are two ways you can tune batch fetching:
• Batch fetching at CFC level: This allows batch fetching of the proxied objects and is applied to one-to-one and
many-to-one relationship. For example, consider artwork and artist example where there are 25 art instances
loaded in the request (ORM session). Each artwork has a reference to the artist and the relationship is lazy.
Therefore, art objects contain the proxied object for artist. If you now iterate through all the art objects and call
on each, by default 25 SELECT statements are executed to retrieve the proxied owners, one for each
getartist()
artist proxy object. This can be batched by specifying the
<cfcomponent table="artist" batchsize="10" ...>
When you call
getartist()
request.
So for 25 art objects, this type of batch fetching makes Hibernate execute a maximum of three queries in batches of
10, 10, and 5.
• Batch fetching at collections: This allows batch fetching of value collections, one-to-many or many-to-many
relationships that are uninitialized. For example, consider artist-art one-to-many relationship where there are 25
artists loaded and each artist has a lazy collection of artworks. If you now iterate through the artists and call
on each, by default 25 SELECT statements are executed, one for each artist to load its art objects. This
getarts()
can be optimized by enabling batch fetching, which is done by specifying
property:
Example:
In artist.cfc:
<cfproperty name="art" fieldtype="one-to-many" cfc="art" fkcolumn="artistId" lazy="true"
batchsize="10">
on the relationship property definition in the CFC.
lazy="false"
'batchsize'
on the first art object, it batch fetches 10 artist objects that are proxied in the current
Last updated 1/20/2012
attribute on the artist CFC:
on the relationship
"batchsize"
589

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents