我想使用以下参数显示所有未回答但未回答的检查表(响应检查表在ResponsesCheckLists表中):idequipement和idMission。
@Query("SELECT check,resp,eq FROM Equipements eq INNER JOIN CheckLists check WHERE eq.idEquipements = check.equipements.idEquipements LEFT JOIN ResponsesCheckLists resp ON check.idCheckLists=resp.CheckLts.idCheckLists AND resp.Respmission.idMission = :idmiss WHERE eq.idEquipements = :idEqp ")
public List<ResponsesCheckLists> ListCheckListsNonRepondu(@Param("idEqp") long idEqp, @Param("idmiss") long idmiss);
运行此查询后,我显示以下错误消息:
antlr.NoViableAltException: unexpected token: LEFT
------
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: LEFT near line 1, column 148 [SELECT check,resp,eq FROM com.SSC.DAO.Entities.Equipements eq INNER JOIN CheckLists check WHERE eq.idEquipements = check.equipements.idEquipements LEFT JOIN ResponsesCheckLists resp ON check.idCheckLists=resp.CheckLts.idCheckLists AND resp.Respmission.idMission = :idmiss WHERE eq.idEquipements = :idEqp ]
------
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'responsesCheckListsRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.SSC.DAO.JPARepository.ResponsesCheckListsRepository.ListCheckListsNonRepondu(long,long)!
EDIT1:
@Query("SELECT check,resp,eq FROM Equipements eq INNER JOIN CheckLists check ON eq.idEquipements = check.equipements.idEquipements"
+ " INNER JOIN ResponsesCheckLists resp ON check.idCheckLists=resp.CheckLts.idCheckLists AND resp.Respmission.idMission = :idmiss AND eq.idEquipements = :idEqp ")
public List<ResponsesCheckLists> ListCheckListsNonRepondu(@Param("idEqp") long idEqp, @Param("idmiss") long idmiss);
Edit1错误;
引起:java.lang.IllegalStateException:节点没有数据类型: org.hibernate.hql.internal.ast.tree.IdentNode + - [IDENT] IdentNode: &#39;检查&#39; {originalText =校验}
antlr.SemanticException:期望加入的路径!
引起:java.lang.IllegalArgumentException:验证失败 查询方法public abstract java.util.List com.SSC.DAO.JPARepository.ResponsesCheckListsRepository.ListCheckListsNonRepondu(长,长)!
EDIT2:
@Query("SELECT check , resp , eq FROM Equipements eq INNER JOIN CheckLists check ON eq.idEquipements = check.equipements.idEquipements"
+ " INNER JOIN ResponsesCheckLists resp ON check.idCheckLists=resp.CheckLts.idCheckLists AND resp.Respmission.idMission = :idmiss AND eq.idEquipements = :idEqp ")
public List<ResponsesCheckLists> ListCheckListsNonRepondu(@Param("idEqp") long idEqp, @Param("idmiss") long idmiss);
Edit2的错误:
引起:java.lang.IllegalStateException:节点没有数据类型: org.hibernate.hql.internal.ast.tree.IdentNode + - [IDENT] IdentNode: &#39;检查&#39; {originalText =校验} antlr.SemanticException:期望加入的路径!
如何更正此查询?
提前谢谢
答案 0 :(得分:1)
你有一个Spring注释(@Query
)指定一个JPQL查询。您的JPQL查询应遵循语法highlighted in this link(以及JPA规范)。可悲的是,你还没有跟着它。
SELECT {result} FROM {from} WHERE {where} ...
任何&#34;加入&#34;必须进入FROM子句。您已经在FROM子句中放置了一个JOIN,但由于您只知道的原因,您决定在WHERE子句中添加另一个JOIN!实际上你在那个废话中有2个WHERE子句。
无法告诉您您的查询应该是什么,因为您不会发布您的实体,因此我们不会看到他们之间的关系,甚至您想要实现的目标。我们只能指出您的错误