hi gregor,

imo this is a good example for user alias:

you'll need two criteria because an article can not have name1 and name2 :

Criteria crit1 = new Criteria();
Criteria crit2 = new Criteria();

crit1.setAlias("crit1");
crit1.addEqualTo("allArticlesInGroup.articleName","Article 1");

crit2.setAlias("crit2");
crit2.addEqualTo("allArticlesInGroup.articleName","Article 2");

crit1.addAndCriteria(crit2);
Query q = QueryFactory.newQuery(ProductGroup.class,crit1);

hth
jakob


Gregor Heinze wrote:


Thanks for your fast reply.

Maybe I was unclear? It's not the articles I'm about it's the product groups
containing the articles. So I'm trying to say: "Give me all product groups
that have an article where article.name = 'Article 1' AND an article where
article.name = 'Article 2'".
Or to say it in Java, a match would be
if (productGroup.allArticlesInGroup.contains("Article 1") &&
productGroup.allArticlesInGroup.contains("Article 2"))



-----Urspr�ngliche Nachricht-----
Von: Michael Duffy [mailto:[EMAIL PROTECTED]
Gesendet: Dienstag, 18. M�rz 2003 16:31
An: OJB Users List
Betreff: Re: Query against Collection with more than one addEqualTo
statement.



The empty collection result makes perfect sense if the
default behavior is to AND criteria together.  None of
your articles have both names set (exclusion at work),
so nothing comes back.

Aren't you trying to say "Give me all the articles
where name = 'Article 1' OR name = 'Article 2'"?

If I understand correctly, I think you want to use
either the addOrCriteria or addIn methods. - MOD

--- Gregor Heinze <[EMAIL PROTECTED]> wrote:


For the sake of simplicity, I refer to the class
model from the tutorial
"Advanced Object Relational Mapping techniques" to
explain my problem. It
seems to be quite simple but I wasn't able to figure
it out correctly.
All I want to do is to get all ProductGroup's which
have an Article with the
articleName "Article 1" _and_ an Article with the
articleName "Article 2" in
its allArticlesInGroup Vector.
Using the PersistenceBroker API I wrote the
following:

Criteria crit = new Criteria();
crit.addEqualTo("allArticlesInGroup.articleName",
"Article 1");
crit.addEqualTo("allArticlesInGroup.articleName",
"Article 2");
Query q = QueryFactory.newQuery(ProductGroup.class,
crit);

Unfortunately this approach does not work and I
always get an empty result
collection. Using only one addEqualTo statement
works as expected but using
two of them won't.
Anyone has an idea how to do this? Any help is
appreciated!

Thanks in advanced,
Gregor





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to