diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/BadJpqlGrammarErrorListener.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/BadJpqlGrammarErrorListener.java index 66b64a0314..a2edc2d911 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/BadJpqlGrammarErrorListener.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/BadJpqlGrammarErrorListener.java @@ -29,14 +29,21 @@ class BadJpqlGrammarErrorListener extends BaseErrorListener { private final String query; + private final String grammar; + BadJpqlGrammarErrorListener(String query) { + this(query, "JPQL"); + } + + BadJpqlGrammarErrorListener(String query, String grammar) { this.query = query; + this.grammar = grammar; } @Override public void syntaxError(Recognizer recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { - throw new BadJpqlGrammarException("Line " + line + ":" + charPositionInLine + " " + msg, query, null); + throw new BadJpqlGrammarException("Line " + line + ":" + charPositionInLine + " " + msg, grammar, query, null); } } diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/BadJpqlGrammarException.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/BadJpqlGrammarException.java index 6cc24630ef..ab3b51b7b3 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/BadJpqlGrammarException.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/BadJpqlGrammarException.java @@ -30,7 +30,11 @@ public class BadJpqlGrammarException extends InvalidDataAccessResourceUsageExcep private final String jpql; public BadJpqlGrammarException(String message, String jpql, @Nullable Throwable cause) { - super(message + "; Bad JPQL grammar [" + jpql + "]", cause); + this(message, jpql, "JPQL", cause); + } + + BadJpqlGrammarException(String message, String grammar, String jpql, @Nullable Throwable cause) { + super(message + "; Bad " + grammar + " grammar [" + jpql + "]", cause); this.jpql = jpql; } diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryEnhancer.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryEnhancer.java index 80d8a6eb0d..7f02ce3ecf 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryEnhancer.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryEnhancer.java @@ -72,7 +72,13 @@ static

ParserRuleContext parse(String query, Function ParserRuleContext parse(String query, Function