Hibernate version: 3.0.5
Code between sessionFactory.openSession() and session.close():
I have a criteria query that works but with unintended behavior
Code:
list = s.createCriteria(StuMaster.class)
.add(Expression.eq("instidq", instidq))
.add(Expression.eq("instid", instid))
.add(Expression.eq("stuno", stuno))
.createCriteria("stuAcadrecs")
.add(Expression.eq("evalflg", "E"))
.list();
stuMaster is an object with a property(called stuAcadrecs) to contain a set of StuAcadrecs.
What I get is 6 results in that list of stuMaster Objects joined with the stuAcadrec data (but it gets cast to Stumaster cause you have to) so the stuAcadrec data is lost. Then, in each of those stuMaster objects, the stuAcadrecs field is full of 13 stuAcadrecs when it should only be 6(because only 6 stuAcadrecs match the condition of evalflg='E').
(In the logs I can see the original six results, then I can see hibernate run 13 more queries to the db to populate the stuAcadrecs field)
Is there a way to return a stuMaster with its children set to match the query condition of evalflg='E' so that only 6 are returned instead of all 13?
I've tried various combinations of these as well
Code:
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
// .setProjection( Projections.projectionList()
// .add( Projections.property("stm.stuAcadrecs"), "stuAcadrecs" )
// )
// .setResultTransformer( new AliasToBeanResultTransformer(StuMaster.class) )