【问题标题】:Hibernate HQL: two levels of joinsHibernate HQL:两级连接
【发布时间】:2009-03-03 21:27:18
【问题描述】:

我是 HQL 新手,有以下表格关系:

  • Term 有很多 Definitions
  • Definition 有很多 DefinitionProducts
  • DefinitionProducts 有一个 Product

我想获取至少有一个DefinitionTerms 的列表,其中至少有一个DefinitionProduct 有一个特定的Product

这是我最好的尝试(在 Grails 中):

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

通过上述,我得到一个“def.definitionProducts is not mapped”异常。

【问题讨论】:

    标签: hibernate grails hql


    【解决方案1】:

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

    【讨论】:

    • 这似乎返回了一个定义产品列表
    • select t from Term t join t.definitions def join def.definitionProducts dp where dp.product=?
    • 是的!非常感谢。在 grails 中,我只需将调用从 Term.findAll 切换到 Term.executeQuery 就可以了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-13
    相关资源
    最近更新 更多