-->
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 with subquery problem
PostPosted: Sat May 23, 2009 3:28 am 
Newbie

Joined: Wed Oct 24, 2007 5:49 pm
Posts: 5
Hi,
I'm having problem with writing correct hql query. I've struggled for a week and finally gave up. I'm actually using Grails, but the problem is related to hibernate since grails uses it under the hood. Below you can see my domain classes and associations between them (I've simplified them and omitted not vital parts to this discussion. As I said
I have them actually written in groovy and grails, not java).

Code:
public class Company {
   @OneToMany
   public Collection<Offer> offers
}

public class Offer {
   @ManyToOne
   public Simulation simulation
   
   @ManyToOne
   public Company company
}

public class Simulation {
   @OneToMany
   public Collection<Offer> offers
}


I want to query all companies that submitted offer to a particular simulation given simulation id. I would also like to get list of companies that didn't participate.
I tried something like that:
query for participants:
Code:
"from Company c join fetch c.offers o join fetch o.simulation s where :id in (select s.id from s)"

query for non-participants:
Code:
"from Company c join fetch c.offers o join fetch o.simulation s where :id not in (select s.id from s)"

I fetch explicitly because otherwise I've been receiving exceptions. I've also tried:
Code:
"from Company c join fetch c.offers o join fetch o.simulation s where :id = any (select s.id from s)"

or
Code:
"from Company c join fetch c.offers o join fetch o.simulation s where :id = any indices(s)"


but without any lack (I'm not sure about difference between "= any", " = some" and " in " or elements(), indices(), http://docs.jboss.org/hibernate/stable/core/reference/en/html/queryhql-expressions.html don't mention that). The very top query for participants worked partially (returned some tuples), but never query for getting companies that didn't participate.
(Company can have their offers' collection empty. I'm not sure it this has something to do with)

I appreciate for any help, and sorry for my English.


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.