-->
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.  [ 4 posts ] 
Author Message
 Post subject: newbie: recommended practice for locating child object
PostPosted: Thu May 05, 2005 11:29 pm 
Regular
Regular

Joined: Fri Oct 01, 2004 2:19 am
Posts: 111
Location: Melbourne, Australia
I was wondering what the recommended practice is for locating a child object within a parent using some property.

consider the following model fragment:
Code:
class Parent
{
   Set<Child> children;
   ...
}
class Child
{
    int prop1;
    String prop2;
    SomeClass ref;
}
class SomeClass{ ... };


I would like to find a chilld of Parent p with a particular SomeClass ref
value.

I know I could go down the path of running a query and efficiently
retrieve the appropriate child, using a DAO etc.

However, some times it may be arguably part of the domain model interface to provide such access method in Parent:
Code:
class Parent
{
   Child getChildUsingSomeClassRef( SomeClass ref )
   {
      ... iteration ....
   }
}


especially if persistence is abstracted away.

This, of course leads to the n+1 query behaviour when iterating, causing
a significant penalty during runtime.

What are the recommended solutions for this problem that people out
there are using?

_________________
Cheers,

Bonny

please don't forget to rate :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 11:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Don't forget the power of the querying abilities of hibernate. Write a simple HQL query to find the child you are after.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 08, 2005 8:35 pm 
Regular
Regular

Joined: Fri Oct 01, 2004 2:19 am
Posts: 111
Location: Melbourne, Australia
David,
david wrote:
Don't forget the power of the querying abilities of hibernate. Write a simple HQL query to find the child you are after.


I don't dispute the power of Hibernate and it certainly has it's place. What
I was after was more of a response to a 'poll' sort of thing where people
state which method they use.
Again, whilst Hibernate certainly allows me to find the right child in the
scenario I describe above very easily, it also moves a responsibility of
Parent to an external object, a DAO of some sort. And while this is A
Good Thing for performance reasons, it also means that an operation
that is part of my domain model is now somewhere else, and I wanted
peoples' opinion on this.

_________________
Cheers,

Bonny

please don't forget to rate :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 08, 2005 10:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Understand your point. I use HQL mostly. There is nothing wrong with walking the domain class structure either just a risk (depending on the situation) that many SQLs could be generated in the process. This may or may not be OK - depends on the judgement of the developer et al.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.