-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Criteria and filling children according to constraints
PostPosted: Thu Sep 29, 2005 11:31 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
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) )

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 3:23 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
bahhh. often times we make things more difficult than they have to be.
fixed using 2 lines of simple hql

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 12:46 pm 
Newbie

Joined: Thu Nov 10, 2005 12:35 pm
Posts: 6
What were the lines of HQL?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 1:02 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I just ended up running a simple hql join

Code:
from StuMaster stu join stu.Acadrecs where evalflg='E';


I also set the relationship to lazy="false".

what this returns is a list of arrays of objects. The list was size 6 and each array of objects had 2 objects in them

each array had the same stuMaster Object in them, and also had 1 of 6 desired StuAcadrec objects.

So I got 7 objects back from the database1 StuMaster, and 6 StuAcadrecs) instead of 6*13 objects.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.