带子句的 grails HQL

标签 grails hql

由于我之前的问题没有得到解答,我想再问一次。

高品质

    from Agenda agr 
    inner join agr.agenda a with a.employee.id = :employeeId
    left join agr.employer wgr
    left join wgr.contracts cnt with agr.date >= cnt.validFrom and agr.date < cnt.ValidUntil

我收到了消息
with-clause referenced two different from-clause elements

native SQL
left join contract cnt
    on agr.wgv_id = cnt.wgv_id
       and agr.date >= cnt.validFrom
       and agr.date < cnt.validTill

在上一个问题中,建议是使用 HQL 和 'with' 子句。这可能是一种方式吗?建议?

最佳答案

{替换}

如果您希望捕获空记录,则只需要左连接,否则只需使用连接

from Agenda agr
    inner join agr.agenda a with a.employee.id = :employeeId
    left join agr.employer wgr
    left join wgr.contracts cnt
where agr.date >= :start
    and agr.date <= :end
    and ((agr.date >= cnt.validFrom and agr.date < cnt.validTill) or agr.employer is Null)

通缉
from Agenda agr
        inner join agr.agenda a with a.employee.id = :employeeId
        left join agr.employer wgr
        left join wgr.contracts cnt with agr.date >=cnt.validFrom and agr.date < cnt.valifTill
    where agr.date >= :start
        and agr.date <= :end

关于带子句的 grails HQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32475219/

相关文章:

java - 如何将商品订购 HQL 转换为过滤查询?

mysql - 如何将一天添加到sql日期?

java - JPA/hibernate : code based validation of jpa queries

java - Hibernate 命名查询复制粘贴

java - hql查询获取最近1个月的记录

java - Grails 应用程序占用太多内存

image - Grails:-如何在文件系统中显示图像

hibernate - GORM IdentityEnumType 与 Grails 2.5.6 映射 NPE

generics - Grails 类型检查/CompileStatic/GrailsCompileStatic

grails - 错误:以下插件由于缺少依赖项而无法加载: