Hi All
I've been mucking with the Criteria API and I have a question. Basically, I've got a list of Users (Person class) that each have a Set of Traits. I have a query screen that allows me to checkbox different Traits to search by.
Code:
Criteria personCrit = session.createCriteria(Person.class);
Criteria traitCrit = personCrit.createCriteria("profileTraits");
personCrit.setMaxResults(pageSize);
personCrit.setFirstResult((pageNum-1)*pageSize);
It's going to be a pageable resultset, so I set first and max results.
Now I get my ids' from my form and put them into the Trait expression.
Code:
Integer[] choices = form.getIntegerArray(key);
// loop through and
for (int i = 0; i < choices.length; i++)
{
traitCrit.add(Expression.eq("traitID", choices));
}
The big problem here is that the query is returning one of the main objects (Person) for each trait that the person matches! This makes sense in SQL:
Code:
select a.* from person a, person_trait b where
a.personid = b.personid and
b.trait_id in (1,2,3)
but this is not really the ideal query. What I'm REALLY after is
Code:
select UNIQUE a.* from person a, person_trait b where
a.personid = b.personid and
b.trait_id in (1,2,3)
Note that I can't do "postprocessing" on the list that I can do since this would screw up the pagesize and pagenum.
What is the solution? I can't find anything in the API that deals with this!
Thanks
- Jason