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
|