gpt4 book ai didi

java - 加入 Hibernate HQL

转载 作者:行者123 更新时间:2023-11-29 06:10:33 26 4
gpt4 key购买 nike

我正在尝试对 hql hibernate(版本 3.5.3)进行查询,该查询包括不同表(4 个表)之间的多个连接。这是查询:

     SELECT (lot of stuff) 
FROM InvestigationRule as ir
JOIN InvestigationFormula as if ON (ir.tb33InvestigationFormula=if.idInvestigationFormula)
JOIN InvestigationEvent as ie ON (ir.tb27InvestigationEvent=ie.idInvestigationEvent)
JOIN InvestigationSectionEvent as ise ON (ie.eventSection=ise.sectionEventsCod)

我第一次遇到语法错误,谁能帮我解决这个问题,谢谢。

ps:我知道即使不使用 JOIN 命令我也可以进行连接,这是原始查询:

    SELECT (lot of stuff)  
FROM InvestigationRule AS ir,
InvestigationEvent as ie,
InvestigationSectionEvent as ise,
InvestigationFormula as if
WHERE ir.dateValidityEnd is null
AND ir.tb27InvestigationEvent = ie.idInvestigationEvent
AND ir.tb33InvestigationFormula = if.idInvestigationFormula
AND ie.eventSection = ise.sectionEventsCod

但我不能使用这种形式,因为它在 MySql 数据库上创建了多个 CROSS JOIN(s),这是不好的。

最佳答案

if 是 SQL 中的关键字,因此您必须更改别名:

SELECT (lot of stuff) 
FROM InvestigationRule as ir
JOIN InvestigationFormula as iform ON (ir.tb33InvestigationFormula=iform.idInvestigationFormula)
JOIN InvestigationEvent as ie ON (ir.tb27InvestigationEvent=ie.idInvestigationEvent)
JOIN InvestigationSectionEvent as ise ON (ie.eventSection=ise.sectionEventsCod)

HQL 看起来像:

SELECT (lot of stuff) 
FROM InvestigationRule ir
JOIN ir tb33InvestigationFormula iform
JOIN ir.tb27InvestigationEvent ie
JOIN ie.eventSection ise

关于java - 加入 Hibernate HQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38478230/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com