After turning on logging on my JDBC driver, I noticed
that a seperate query statement was issued for each
child object in a parent child relationship (i.e.
ProductGroup --> Product). 

Query   "SELECT
AA_PRODUCT_GROUP.PROD_GROUP_ID,AA_PRODUCT.PRODUCT_ID,AA_PRODUCT_GROUP.CATEGORY
FROM AA_PRODUCT_GROUP LEFT OUTER JOIN AA_PRODUCT ON
AA_PRODUCT_GROUP.PROD_GROUP_ID=AA_PRODUCT.PRODUCT_GROUP_ID"
 execution time: 0       result set fetch time:  0

Followed by...

Query   "SELECT
AA_PRODUCT.NAME,AA_PRODUCT.PRODUCT_GROUP_ID FROM
AA_PRODUCT WHERE AA_PRODUCT.PRODUCT_ID=1"     
execution time: 70      result set fetch time:
0
Query   "SELECT
AA_PRODUCT.NAME,AA_PRODUCT.PRODUCT_GROUP_ID FROM
AA_PRODUCT WHERE AA_PRODUCT.PRODUCT_ID=2"     
execution time: 0       result set fetch time:
0
Query   "SELECT
AA_PRODUCT.NAME,AA_PRODUCT.PRODUCT_GROUP_ID FROM
AA_PRODUCT WHERE AA_PRODUCT.PRODUCT_ID=3"     
execution time: 70      result set fetch time:
0
Query   "SELECT
AA_PRODUCT.NAME,AA_PRODUCT.PRODUCT_GROUP_ID FROM
AA_PRODUCT WHERE AA_PRODUCT.PRODUCT_ID=4"     
execution time: 10      result set fetch time:
0

In some instances I would want to load the children
(i.e. a ProductGroup detail page) and other cases I
wouldn't want to spend time loading the children (i.e.
a ProductGroup search results page that didn't display
any Product info).  So...my first question, is there a
way to specify lazy loading of a field at runtime?

In an effort to optimize, I turned the field "lazy"
attribute value from false to true in the ProductGroup
mapping, which resulted in just the first sql query
being issued...so far so good.  However, after closing
the query via a database.close() call, and returning
the ProductGroup object to the presentation tier, I
got the following exception when trying to access the
ProductGroup's Products:

java.lang.RuntimeException: Transaction is closed!

org.exolab.castor.persist.RelationCollection$IteratorImp.lazyLoad(RelationCollection.java:282)

org.exolab.castor.persist.RelationCollection$IteratorImp.next(RelationCollection.java:266)

Which leads me to my second question: How are lazy
loaded collections properly used in a web app
environment?  Am I supposed to leave the database
object open until the presentation tier is done with
the query.  Am I supposed to loop through the search
results (effectively loading them) before returning
them to the presentation tier?

Thanks,
Jon



----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to