santo2 wrote:
Hey guys, I'm also having the same issue.. i'm having really nice objects with lots of collections in it, but when loading a list this is of course not that great. i'm getting quite allot of information that I don't need, and i would like to keep working with Criteria because i'm not support HQL in my methods.
I've built some easy methods where in you can add a list of criteria to get data out of a WCF Service (.Net of course)
By the hand of your explenation of implementing Projection and extending IdentifierProject I actually still don't know what to do..
Can you give a small example please?
Thanks allot
Here you are:
Code:
Criteria criteria = session.createCriteria(MyClass.class);
Projection listProjection = new NoJoinProjection(MyClass.class);
criteria.setProjection(listProjection);
return criteria.list();
And NoJoinProjection is like:
Code:
public class NoJoinProjection extends IdentifierProjection {
private Class<?> projectionClass;
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
return new Type[] { new ManyToOneType(projectionClass.getName()) };
}
public NoJoinProjection(Class<?> projectionClass) {
super();
this.projectionClass = projectionClass;
}
}
The drawback is that all related entities get loaded in separate SQL queries. And all EAGER collections get loaded anyway, but you don't get multiplied number of resultes any more.