views:

766

answers:

1

I am new to HQL and have the following table relationships:

  • Term has many Definitions
  • Definition has many DefinitionProducts
  • DefinitionProducts has one Product

I want to get the list of Terms that have at least one Definition that has at least one DefinitionProduct that has a specific Product

This is my best attempt (in Grails):

Term.findAll("from Term t, Definition d inner join t.definitions def,  
def.definitionProducts dp where ? = some elements (dp.product)",
Product.get(1))

With the above, I get a "def.definitionProducts is not mapped" exception.

+3  A: 

select t from Term t join t.definitions def join def.definitionProducts dp where dp.product=?

Maurice Perry
That seems to return a list of definitionProducts
Mike Sickler
select t from Term t join t.definitions def join def.definitionProducts dp where dp.product=?
Maurice Perry
Yes! Thanks a lot. In grails, I just had to switch the call from Term.findAll to Term.executeQuery and it worked!
Mike Sickler