I am specifying a Spring Data query using @Query
on a repository method but it is throwing a NoViableAltException
exception.
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.
You are using the Spring Data annotation, @Query
which normally takes a JPQL query string. What you are specifying is a native query SQL string, so you need to modify the annotation and also provide nativeQuery=true
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With