[英]Join on Hibernate HQL
i'm trying to do a query on hql hibernate (version 3.5.3), the query includes several joins between different tables (4 tables). 我正在尝试对hql休眠(版本3.5.3)进行查询,该查询包括不同表(4个表)之间的多个联接。 This is the query: 这是查询:
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)
I met a syntax error on first ON, can someone help me fix this, thx. 我在第一次开机时遇到语法错误,有人可以帮我解决这个问题吗,谢谢。
ps: i know that i can make joins even without using the JOIN command, this is the original query: 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
But i cannot use this form since it creates several CROSS JOIN(s) on the MySql database and this is not good. 但是我不能使用这种形式,因为它在MySql数据库上创建了多个CROSS JOIN(s),但这不好。
if
is a keyword in SQL so you have to Change the alias: 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 Looks like: HQL看起来像:
SELECT (lot of stuff)
FROM InvestigationRule ir
JOIN ir tb33InvestigationFormula iform
JOIN ir.tb27InvestigationEvent ie
JOIN ie.eventSection ise
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.