-->
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.  [ 2 posts ] 
Author Message
 Post subject: Criteria API and a List of String
PostPosted: Tue Mar 22, 2005 11:07 pm 
Newbie

Joined: Tue Mar 22, 2005 9:42 pm
Posts: 1
Hello All,

I have a bunch of query that needs to be build dynamically so I decided to give the Criteria API a try. I am running into a "syntax" problem and I can't figure out how to write this. For example, lets say I have a User object that as an attribute called groupCd which is a list of group code (list of String object) and I want to retrieve every user that has groupCd A and groupCd B

My HBL query/code would look like this
List groupCd = new ArrayList();
groupCd.add("A");
groupCd.add("B");
Query q = session.createQuery("from User as user "
+ "inner join user.groupCd as groupCd "
+ "where type in (:groupCd ) ");
q.setParameterList("groupCd", groupCd);
q.list();

What would be the syntax for the Criteria API? Is this possible? So far I have tried a few combination but without success. The last try I made looked like this:

List groupCd = new ArrayList();
groupCd.add("A");
groupCd.add("B");
Criteria criteria = session.createCriteria(User.class);
criteria.createAlias("groupCd", "groupCd");
criteria.add(Expression.in("groupCd", groupCd));

But I think this is not quite rigth. Well I know it is not rigth because I get a net.sf.hibernate.MappingException: collection was not an association: exception. Which I am still not sure what it is but I am still working on it.

So, anyone ever tried something like this? Is it possible?

Thanks

David

Hibernate version: 2.1.6

Name and version of the database you are using: MySQL


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 12:22 pm 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Did you find out what was the answer ?

I'm facing with the same problem. Can somebody paste some links where can be found some more complex examples ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.