【问题标题】:Grails left outer join query HQL or criteria challengeGrails 左外连接查询 HQL 或条件质询
【发布时间】:2013-01-31 14:21:42
【问题描述】:

我是 hql 的新手,尝试了几种我能找到的组合,但我似乎无法为左连接构造正确的 HQL 查询。

我有以下领域模型:

class Company {
    static hasMany = [employees: Employee]
}

class Employee {
    static belongsTo = [
            Company
    ]
}

因此,员工对公司一无所知。现在我想创建一个 hql 查询,它可以满足 没有公司的员工。在 sql 中,我已经使用左连接成功创建了查询,但我似乎无法创建一个标准或 hql 查询来给我一个正确的结果。

关于我如何实现结果的任何线索或提示?

【问题讨论】:

    标签: grails hql grails-orm


    【解决方案1】:

    给你,这行得通:

    Employee.executeQuery("""
    Select e
    from Employee e
    where e not in (Select ce from Company c left join c.employees ce)
    """)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多