Re[2]: AW: Query against Collection with more than one addEqualTo statement.
Hello Jakob, Thanks a lot, this is exactly what I wanted. Thanks again, Gregor JB> hi gregor, JB> imo this is a good example for user alias: JB> you'll need two criteria because an article can not have name1 and name2 : JB> Criteria crit1 = new Criteria(); JB> Criteria crit2 = new Criteria(); JB> crit1.setAlias("crit1"); JB> crit1.addEqualTo("allArticlesInGroup.articleName","Article 1"); JB> crit2.setAlias("crit2"); JB> crit2.addEqualTo("allArticlesInGroup.articleName","Article 2"); JB> crit1.addAndCriteria(crit2); JB> Query q = QueryFactory.newQuery(ProductGroup.class,crit1); JB> hth JB> jakob JB> 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]
Re: AW: Query against Collection with more than one addEqualTo statement.
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]
AW: Query against Collection with more than one addEqualTo statement.
A little mistake in the Java statement. It should be if (productGroup.allArticlesInGroup.contains(a1) && productGroup.allArticlesInGroup.contains(a2)) Where a1.articleName = "Article 1" and a2.articleName = "Article 2". Of course we've to overwrite equals to compare articles by their name ... Whatever, I hope it's clear now. -Ursprüngliche Nachricht- Von: Gregor Heinze [mailto:[EMAIL PROTECTED] Gesendet: Dienstag, 18. März 2003 16:41 An: OJB Users List Betreff: AW: Query against Collection with more than one addEqualTo statement. 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]
AW: Query against Collection with more than one addEqualTo statement.
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]
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] > __ Do you Yahoo!? Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop! http://platinum.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Query against Collection with more than one addEqualTo statement.
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]