Hi David,
With the following code
criteria.addEqualTo("name", 'xxx');
criteria.addEqualTo("elements.filter", 'yyy');
I get A, but alos all elements of th relationship and not only the B
elements where filter ='yyy'. Finaly it's right because the filter= 'yyy' is
a criteria to retrieve A.
I have a big volumetry on B, so I took your advice, to load the collection
programmaticaly. If later I need all elements I have the proxy to navigate
on the relationship.
A solution would be like the following SQL statement:
select B.* from A, B where A.name='xxx' and B.A_id =A.id and B.filter='yyy'
(with A_id foreign key of A in B table)
Thanks a lot for your help.
Gildas
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 27, 2004 10:33 AM
Subject: RE: collection loading and filtering
Hi Gildas,
According to me, the two approachs are not compatible.
- If you are trying to get A and B in only one query:
Then the following code
criteria.addEqualTo("name", 'xxx');
criteria.addEqualTo("elements.filter", 'yyy');
is the way. And you will get A WITH the filtered collection of B.
And I don't see why you don't want to load the relationship, because
a join query is executed because you want the relationships.
- If you try to avoid unnecessary relationships loading:
Then the proxy is the solution. And in this case the filtering cannot
be done automatically. You have to do it programmatically by adding a method
like
A.getB(int yyy) where you implement your filter.
If you are taking of performance, first do it as simple as possible, then
look if you face performance issues.
Personally, I generally choose the second approach and I use the first one
only in case of performance issues (but only monitoring can say what to do).
Then I have two methods:
A getById(); // criteria.addEqualTo("name", 'xxx') and use proxy
A getByIdWithB(); // criteria.addEqualTo("name", 'xxx')
criteria.addEqualTo("elements.filter", 'yyy')
Be also aware that caching the objects increases performance.
If B contains rather stable data, then cache them.
A.getB() will then use the cache instead of generating a SQL.
Hope it helps...
David WIESZTAL.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]