-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Lazy Parent-Child relationships
PostPosted: Fri Sep 12, 2003 1:59 pm 
Regular
Regular

Joined: Fri Sep 12, 2003 12:40 pm
Posts: 65
Hello,

I have a question about Lazy Parent-Child relationships. I've read chapter 8 several times and searched the forum but I come up empty. This question applies to Hibernate 2.0.

We have a series of relationships: Category -> SubCategory -> SubSubCategory -> Part

We have them setup with lazy initialization between the sets.

Our DAO has methods to return Lists of parents and children.

e.g.

Collection findCategories()
Collection findSubCategories(int categoryId)
Collection findSubSubCategories(int subcategoryId)
etc.

These methods are used to populate a series of dropdown boxes in a web application.

For the findSubCategories() method we're implementing a simple:
session.query(" from SubCategory as subcategory ");

We're not loading all of the subsubcategories for obvious reasons. This query returns the foreign keys to Category as it should.

I'm curious about the findSubSubCategories(int subcategoryId) method. Should we use:

SubCategory subcat = (SubCategory)session.load(subcategoryId, SubCategory.class);
return subcat.getSubSubCategories(); // one to many

(This code first loads the subcategories and associated category fk using a left outer join and second loads the subsubcategories)

or is it better to issue a query for this:

session.query(" from Subcategory as subcategory where subcategory.category.id = ? ");

(The queries load the subsubcategories first, and then loads the subcategories and associated category fk using a left outer join.)

Is this just a matter of preference? Is there anyway of eliminating the query to the subcategory, or is this needed to keep the relationships intact.

Each request will be using a new session, since they come through as new requests from the web-client.

Thank you.

P.S. I'm anxiously awaiting the hibernate book.

_________________
- Brian


Top
 Profile  
 
 Post subject: FWIW
PostPosted: Mon Sep 22, 2003 7:32 pm 
Regular
Regular

Joined: Fri Sep 12, 2003 12:40 pm
Posts: 65
FWIW, we ended up doing the former and just loading the children by first doing a session load and then loading the children.

_________________
- Brian


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.