-->
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.  [ 9 posts ] 
Author Message
 Post subject: Help querying a set with session.filter
PostPosted: Fri Nov 21, 2003 2:38 pm 
Newbie

Joined: Thu Oct 23, 2003 1:43 pm
Posts: 10
Location: Calgary, Alberta Canada
I am confused on the use of session.filter to query a collection.

I have a class, Animal, that has a collection of Tattoos. I want to execute a query that selects animals based on the value of the tattoo (tattoo has several properties, value, location, etc.). Session.filter sounds like what I want, except the first parameter to the method is the collection and I am not sure where I obtain the collection from. Do I have to query all animals first (there are no other limiting criteria on the animals selected so I would select every animal in the database!) and then loop through the list of animals calling session.filter for each?

I am hoping to use session.filter to select only animals with a certain tattoo. In essence the SQL I need to end up with is:
Code:
Select animal from animal, tattoo
where animal.id = tattoo.animalId and tattoo.value = 'ABC123'


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 6:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
eh? Why do you think you want to use a filter instead of just an ordinary query?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 7:01 pm 
Newbie

Joined: Thu Oct 23, 2003 1:43 pm
Posts: 10
Location: Calgary, Alberta Canada
Um, because what I want to query on is a property of an element of a collection. While searching the forum for how to do this I saw some similar scenarios where people were directed to use session.filter and referring to the docs, the example in section 7.3.4 of the docs does seem to be exactly what I want to do...?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 7:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You use a join for this.

Code:
from Customer as c inner join c.orders as o where o.total > 100


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 7:41 pm 
Newbie

Joined: Thu Oct 23, 2003 1:43 pm
Posts: 10
Location: Calgary, Alberta Canada
Really?! Damn I feel like an idiot.

What is session.filter for then?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 8:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
For when you do have a collection ;)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 10:29 pm 
Newbie

Joined: Thu Oct 23, 2003 1:43 pm
Posts: 10
Location: Calgary, Alberta Canada
Gavin! LOL! I think I am going crazy - don't I have a collection in my example?!? I think I do, Animal has a collection of Tattoos.....?! :) Or don't I understand collections either?! ;)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 10:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
Session.filter sounds like what I want, except the first parameter to the method is the collection and I am not sure where I obtain the collection from


its for when you want to do:

Code:
session.filter( animal.getTattoos(), "where tattoo.value='ABC123'" );


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 22, 2003 12:03 am 
Newbie

Joined: Thu Oct 23, 2003 1:43 pm
Posts: 10
Location: Calgary, Alberta Canada
Yes, that is exactly what I want to do! Maybe the SQL I put in my initial post caused some confusion. But I realize now I need to provide selection criteria on not only the animal's tattoo collection but properties on animal itself as well (like sex or breed), and it doesn't look like session.filter lets me query on anything but the collection.


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