-->
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: HQL: how to check if one set is contained within another set
PostPosted: Thu Jul 16, 2009 11:42 am 
Newbie

Joined: Thu Jul 16, 2009 11:30 am
Posts: 1
Hi Everyone,

I've got a problem writing a HQL query, I have an object which contains a set of "Berths" and I want all the objects back whos set of "Berths" is contained within a set of "Berths" that I pass to the query.

In Java it would look like this
Code:
Set<Berth> setParameter = getSomeBerthObjects();

for(NetworkIncident ni : allNetworkIncidents){
    if(setParameter.containsAll(ni.getBerthSet())){
         return NetworkIncident;
    }
}


The query i've written so far is
Code:
         select
            ni from NetworkIncidentImpl ni join ni.berths b
         where
            b in (:berths)


But the problem is I get an error
Code:
    org.hibernate.PropertyAccessException: could not get a field value by reflection getter of BerthImpl.id


I've tried changing it so I pass in a set of Long of the berth objects Id and compare with b.id and this then has a cast exception where it says cannot cast from HashSet to Long. It seems its expecting only a single long and not a set. I've also tried an Array with no avail.

Any help would be much appreciated thanks!

edit:

Silly me I found the method setParameterList() on the query and this has allowed me to run the above query. The only problem now is that it will return any NetworkIncident that has atleast 1 berth in the (:berths) set. I need it so that only if all the berths on a network incident are contained in the (:berths) set are returned preferably. :D


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.