-->
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.  [ 5 posts ] 
Author Message
 Post subject: Easy question on how to retrieve a Filtered Set.
PostPosted: Mon May 02, 2005 11:39 am 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Hi,

am using Hibernate 3.0.2 and I guess I have an easy (HQL) query to do, but I dont see how to do it. I want to get a filtered set.

Basically I wanna get all children under a parent where child.OneProperty="test".

In parameter, I have the starting Parent (myParent) Object.

How can I do this in HQL? Or in Criteria?

Thanks.

Etienne.
Montreal


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 12:36 pm 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
HQL would be something like
Code:
from Parent p where p.children.OneProperty='test'


this assumes "children" is the name of the one-to-many relationship (e.g. set)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 12:39 pm 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
... sorry, I think that is wrong (blame it on Monday). Here is what you might do instead

Code:
select c from Parent p join p.children as c where c.OneProperty='test'


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 2:43 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Thanks for the answer,

It helped me to start, but I guess that it misses the parent identification

Instead of :

Code:
select c from Parent p join p.children as c where c.OneProperty='test'


It should maybe be something like:
Code:
select c from Parent p join p.children as c where c.OneProperty='test' and tl.parent=?


and pass the Parent Object in parameter in the Hibernate session.find method.

Etienne.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 2:44 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Should be read:

Code:
select c from Parent p join p.children as c where c.OneProperty='test' and c.parent=?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.