I have figured this out as a result of debugging a problem I am having with getting too many results from my Criterias.
In my system (maybe I am still doing something wrong...) I get one query executed for every single object (or collection thereof) that lives within my mapping hierarchy. What this means is that if you have the following structure:
Code:
class A {
private Map bInstances = new HashMap();
}
class B {
private Map cInstances = new HashMap();
}
class C {
private Long something = new Long(0);
}
Let's say there are two records for class A in the database...
Four records for class B (A1-B1, A1-B2, A2-B3, A2-B4)...
And eight for class C (B1-C1, B1-C2, B2-C3, B2-C4, etc. ...)...
Assuming it is mapped with <one-to-many...> from A to B and B to C...
When you load an instance of class A you will get the following amount of SQL:
one select for the A record and all it's joining etc from the where criteria.
one select for the list of B records that go with A
depending on how things are joined: one or two more selects for the B records (whether you wanted them or not) details
two more selects for the lists of C records for each of the B's.
four selects for the details of the four C records.
As you can see this becomes exponentially large in nature very fast.
In my system I get several pages of sql output when I load one record because I have nested mappings 5 layers deep with mulitple mappings at the fifth level and the exponential amount of queries is staggering but it does seem to run fairly quickly.