what i want to do is something similar to:
q=s.createQuery("from Kitten k where k.parent in (:cats)");
q.setParameterList("cats", catsCollection);
catsCollection contains Cat entities (not IDs!)..
this works flawlessly and is great..
Now I'd like to do the same with the criteria API, but the InExpression class insists that I specify a property name..
I know its possible to do it like this:
Criteria c = s.createCriteria(Kitten.class).add(Expression.in("parent", catsCollection));
but thats not what I want, since im building the criteria dynamically (the resulting query is not always the same), which is the very point of using criteria, right!? I think it would be nice to have an InExpression ctor taking only the collection of entities to match or a special property name like "this" to specify that the collection of values is actually entities of the same kind that has to be matched... something like:
Criteria c = s.createCriteria(Kitten.class).createCriteria("parent").add(Expression.in("this", catsCollection));
or
Criteria c = s.createCriteria(Kitten.class).createCriteria("parent").add(Expression.in(catsCollection));
Can anybody guide me to what I need to change to make this work the right way? (maybe a new InExpression class of my own?) ... please dont suggest any hacks, since thats what I'm trying to avoid..
Im sure it's not hard to change if you know the exact point of attack, so I guess thats what im looking for....
thanks...
|