[英]NoViableAltException while using Spring Data query with Hibernate
I am specifying a Spring Data query using @Query
on a repository method but it is throwing a NoViableAltException
exception. 我在存储库方法上使用
@Query
指定Spring Data查询,但它抛出了NoViableAltException
异常。
This is the repository interface method and annotation I am using: 这是我正在使用的存储库接口方法和注释:
@Query(value="SELECT one.saveLine, two.saveLine FROM (SELECT * FROM SaveOutputTable WHERE saveType = 'R' and seqId = '0' and executionId =:executionIdOne ) one JOIN (SELECT * FROM SaveOutputTable WHERE saveType = 'R' and seqId = '0' and executionId =:executionIdTwo) two ON one.lineId = two.lineId")
public List<ResultCompare> findByParamResult(@Param("executionIdOne") long executionIdOne,@Param("executionIdTwo") long executionIdTwo);
This causes the following error: 这会导致以下错误:
antlr.NoViableAltException: unexpected token: (
at org.hibernate.hql.internal.antlr.HqlBaseParser.fromRange(HqlBaseParser.java:1501) [hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.hql.internal.antlr.HqlBaseParser.fromClause(HqlBaseParser.java:1325) [hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.hql.internal.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:1045) [hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.hql.internal.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:730) [hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.hql.internal.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:323) [hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.hql.internal.antlr.HqlBaseParser.statement(HqlBaseParser.java:186) [hibernate-core-5.0.9.Final.jar:5.0.9.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:279) [hibernate-core-5.0.9.Final.jar:5.0.9.Final]
This error has absolutely nothing to do with Hibernate. 这个错误与Hibernate完全无关。
You are using the Spring Data annotation, @Query
which normally takes a JPQL query string. 您正在使用Spring Data注释,
@Query
通常采用JPQL查询字符串。 What you are specifying is a native query SQL string, so you need to modify the annotation and also provide nativeQuery=true
. 您指定的是本机查询SQL字符串,因此您需要修改注释并提供
nativeQuery=true
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.