-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: "In" Expresssion and collections
PostPosted: Wed Jan 07, 2004 5:55 pm 
Newbie

Joined: Wed Jan 07, 2004 5:30 pm
Posts: 11
Location: SF, CA
Hi there,

I'm wondering about how to get the Criteria API to do something that seems to work fine as HQL. If this topic has been covered over ad nauseum already, I apologize.

I'm trying to restrict a Criteria.list result based off of an "in" Expression placed on the IDs of the criteria object's children. So if I have an Article object, and that article has topics, I want to restrict the results to those where an article's id's are in a certain set, i.e.:
Code:
Criteria criteria = sess.createCriteria(Article.class);
criteria.add(Expression.in("topics", topicIds))

where "topics" is a child collection of Article.

Funny thing, this works in HQL:
Code:
select Article as article from Article where article.topics in ....

however, it seems to choke in the Criteria API. It tries to use the ID of the articles themselves against the "in" list, seemingly not realizing that "Article" even has a property named "topics".

Anyone else run into this problem? Thanks, Dolan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 8:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You cant do such criterias using the criteria API. You can however do this:

Code:
Criteria criteria = sess
    .createCriteria(Article.class)
          .createCriteria("topics").add(Expression.in("id", topicIds));

See http://www.hibernate.org/hib_docs/reference/html/query-criteria.html#query-criteria-s4[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 8:44 pm 
Newbie

Joined: Wed Jan 07, 2004 5:30 pm
Posts: 11
Location: SF, CA
Thanks gloeglm -- that seemed to do the trick!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.