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.