-->
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: HQL for finding a subset in a collection
PostPosted: Thu Apr 27, 2006 4:28 pm 
Regular
Regular

Joined: Wed Sep 29, 2004 11:34 am
Posts: 62
Location: Houston, TX
I need help writing HQL query for the following scenerio:

I have an object Booking which contains People in it. I want to find if a booking contains atleast one person from another booking:

Booking A - {John, Mary, Jane}
Booking B - {Mary, Henry, Joe}

- The return should be a count of 1, because Booking A has Mary and Booking B also has Mary.


Top
 Profile  
 
 Post subject: Re: HQL for finding a subset in a collection
PostPosted: Thu Apr 27, 2006 4:35 pm 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
[quote="dawuad"]I need help writing HQL query for the following scenerio:

I have an object Booking which contains People in it. I want to find if a booking contains atleast one person from another booking:

Booking A - {John, Mary, Jane}
Booking B - {Mary, Henry, Joe}

- The return should be a count of 1, because Booking A has Mary and Booking B also has Mary.[/quote]

Hello Friend:

Try this:

select a.person.name From Booking A where
a.person.name in (select b.person.name from Booking B).


requests for comments.


Top
 Profile  
 
 Post subject: Re: HQL for finding a subset in a collection
PostPosted: Thu Apr 27, 2006 4:43 pm 
Regular
Regular

Joined: Wed Sep 29, 2004 11:34 am
Posts: 62
Location: Houston, TX
neketsushonen wrote:
Hello Friend:

Try this:

select a.person.name From Booking A where
a.person.name in (select b.person.name from Booking B).


requests for comments.


Thank you for your reply, however the only problem is that the Booking A contains more than one person, meaning that the Booking has a collection of people, so it would not be b.person rather it would be b.personset.person.name which I don't really think it would work!


Top
 Profile  
 
 Post subject: Re: HQL for finding a subset in a collection
PostPosted: Thu Apr 27, 2006 4:50 pm 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
[quote="dawuad"][quote="neketsushonen"]
Hello Friend:

Try this:

select a.person.name From Booking A where
a.person.name in (select b.person.name from Booking B).


requests for comments.[/quote]

Thank you for your reply, however the only problem is that the Booking A contains more than one person, meaning that the Booking has a collection of people, so it would not be b.person rather it would be b.personset.person.name which I don't really think it would work![/quote]


You are rigth... i have ignore that point...

You problem is very interest. I have to think a lot too...

I have a worst solution:

do it with JAVA HashMap...

Hehe...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 3:56 am 
Regular
Regular

Joined: Wed Aug 25, 2004 6:23 am
Posts: 91
How about something like this?

Code:
select a From Booking a where
any elements(a.personset) in (select b.personset from Booking b)


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.