Hello All,
I figured out an answer to my question from yesterday and I figured I would share with you all.
My problem boiled down to having a criteria query return the objects of a set within an object so I could do pagination on these objects.
I found this page:
http://blog.hibernate.org/cgi-bin/blosx ... ql_and_sql
Which pointed me to Result Transformers. I wanted to try to get the query to return the members of the underlying set rather than the root entity of my query. I found the PassThroughResultTransformer which returned a mapping of the objects that I wanted with their root entities. After downloading the source for this class and modifying it, I came up with something that worked.
My Criteria Query:
Code:
Criteria c=sessionFactory.getCurrentSession().createCriteria(MailingList.class)
.add(Expression.eq("id", listId))
.add(Expression.eq("siteId", siteId))
.createCriteria("recipients")
.setResultTransformer(new RecipientResultTransformer())
.setMaxResults(10).setFirstResult(10*page.intValue());
RecipientResultTransformer:
Code:
public class RecipientResultTransformer implements ResultTransformer {
public List transformList(List collection) {
return collection;
}
public Object transformTuple(Object[] tuple, String[] aliases) {
return tuple[0]; //Gets the lowest level criteria of the underlying result
}
}
If anyone from the Hibernate Team could suggest improvements, or ways which I was lucky to get it work, please do so, I'd like to try to reuse this technique in other places of my application.