-->
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.  [ 1 post ] 
Author Message
 Post subject: Need a definitive answer on loading a collection subset
PostPosted: Fri Jul 14, 2006 2:56 pm 
Beginner
Beginner

Joined: Mon Jan 23, 2006 12:01 pm
Posts: 46
Hi,

I've been around this block a couple hundred times now, and I still can't make it work. Maybe it's not possible with Hibernate - could someone answer this one for me?

Here's the db model (tables):
PARENT - CHILD - GRAND_CHILD

Here's the data:

PARENT: parent_id=0

CHILD: child_id=0, parent_id=0
CHILD: child_id=1, parent_id=0

GRAND_CHILD: grand_child_id=0, child_id=0 <<< looking for this one
GRAND_CHILD: grand_child_id=1, child_id=1

Those are my Hibernate classes:
Parent, Child, GrandChild

Parent has a collecion of Child objects (children; one-to-many), and Child has a collection of GrandChild objects (grandChildren; one-to-many).

My query is this:

Criteria c=session.createCriteria(Parent.class).createCriteria("children").createCriteria("grandChildren");
c.add(Expression.eq("grandChildId",0));

Here's my problem: this query always returns single Parent object, but the children collection of the Parent class contains both Child records (with their respective grandChildren records).

Is there a way to tell Hibernate not to load the Child element that does not match the query? From what I can tell the query is applied to top-level table only (Parent), and then everything below that is loaded without any consideration for placed criteria.

So I'd like to know if this can be done - loading only the records (and the children) that match the criteria (so only one Child would be in the collection, not two).
Also, I'd like to know if this can be done WITHOUT the use of Hibernate filters.
I'd greatly appreciate it if someone experienced with Hibernate could answer this for me, one way or another.
Thanks,

Bratek


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

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.