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?