我有这个抛出querySyntaxException的HQL请求:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: with-clause referenced two different from-clause elements [SELECT patDataset.patient.sId , patData ,proDataset.professional.sId, proData FROM com.inovelan.cloud.persistence.server.entities.DataSet patDataset INNER JOIN patDataset.patient patient with patient. sId in (:patientSidList) LEFT JOIN patient.patientProfessionals ppRole with ppRole.id.roleCodingOidcodesystem= :codeSystem AND ppRole.id.roleCodingCode=:codingCode LEFT JOIN ppRole.professional proRole LEFT JOIN proRole.dataSet proDataset with proDataset.archive =:archive LEFT JOIN proDataset.dataProfessionals proData with proData.itemDefinition.id.id in (:proItemDefs) INNER JOIN patDataset.dataSetDefinition patDatasetDef with patDatasetDef.id.id in(:patDatasetDefIdList) INNER JOIN patDataset.dataPatients patData LEFT JOIN patDataset.dataPatients data_patient_PAT_SEXE with ( data_patient_PAT_SEXE.itemDefinition.id.id=:data_patient_PAT_SEXE AND patDataset.dataSetDefinition.id.id ='DIRECTORY_PATIENT') LEFT JOIN patDataset.dataPatients data_patient_PAT_NOM_NAISSANCE with ( data_patient_PAT_NOM_NAISSANCE.itemDefinition.id.id=:data_patient_PAT_NOM_NAISSANCE AND patDataset.dataSetDefinition.id.id ='DIRECTORY_PATIENT') LEFT JOIN patDataset.dataPatients data_patient_PAT_PRENOM with ( data_patient_PAT_PRENOM.itemDefinition.id.id=:data_patient_PAT_PRENOM AND patDataset.dataSetDefinition.id.id ='DIRECTORY_PATIENT') WHERE patDataset.archive=:archive AND patient.active=:patientState AND ( patDatasetDef.id.id =:dataset_def_pat_DIRECTORY_PATIENT AND patData.itemDefinition.id.id in (:itemdef_list_pat_DIRECTORY_PATIENT) ) AND patDataset.date = (SELECT MAX(patDataset2.date) FROM com.inovelan.cloud.persistence.server.entities.DataSet patDataset2 WHERE patDataset2.dataSetDefinition.id.id = patDataset.dataSetDefinition.id.id AND patDataset2.patient.sId = patDataset.patient.sId) ORDER BY (CASE WHEN data_patient_PAT_SEXE.stringValue IS NULL then 1 ELSE 0 END), data_patient_PAT_SEXE.stringValue ASC,(CASE WHEN data_patient_PAT_NOM_NAISSANCE.stringValue IS NULL then 1 ELSE 0 END), data_patient_PAT_NOM_NAISSANCE.stringValue ASC,(CASE WHEN data_patient_PAT_PRENOM.stringValue IS NULL then 1 ELSE 0 END), data_patient_PAT_PRENOM.stringValue ASC]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:91)
at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:109)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:284)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:206)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:131)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:93)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1836)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:342)
我提取了请求以使其更易理解,这种“左连接”的原因是对元数据进行排序(它并不总是添加到请求中):
SELECT patDataset.patient.sId,
patData
FROM DataSet patDataset
INNER JOIN patDataset.patient patient
INNER JOIN patDataset.dataSetDefinition patDatasetDef WITH patDatasetDef.id.id IN(:patDatasetDefIdList)
LEFT JOIN patDataset.dataPatients data_patient_PAT_SEXE WITH (data_patient_PAT_SEXE.itemDefinition.id.id='SEXE'
AND patDatasetDef.id.id ='DIRECTORY_PATIENT')
WHERE patDataset.archive=:archive
AND patient.active=:patientState
ORDER BY (CASE
WHEN data_patient_PAT_SEXE.stringValue IS NULL THEN 1
ELSE 0
END), data_patient_PAT_SEXE.stringValue ASC
我已经在SQL中尝试过,我想做的事情完美无缺
LEFT OUTER JOIN dataPatient datapatien1 ON dataset.sId=datapatien1.dataSetSid
AND (datapatien1.itemDefinitionId ='SEXE')
AND datasetdef.id ='DIRECTORY_PATIENT'
我在hibernate https://hibernate.atlassian.net/browse/HHH-7321听说过这个问题 但我使用hibernate 5.2,它应该没问题
我已经检查了类似的问题,但没有人有相同的案例
感谢您的帮助
答案 0 :(得分:0)
由于“patDatasetDef.id.id”语句,HQL会生成此错误。它在解析此语句时遇到问题。
相反,您必须对连接对象使用连接操作,如下所示: 选择mother,offspr,mate.name 来自DomesticCat作为母亲 内部加入母亲。作为伴侣 left outer join mother.kittens as offspr