我在我的RepositoryBean中有这个查询:
Query(value = "TRUNCATE TABLE #{#entityName}", nativeQuery = true)
@Modifying
void truncateTable();
字符串
这曾经与Sping Boot 3.0.x一起使用。然而,在升级到Spring 3.1.2之后,我从HQL解析器收到一个错误,因为TRUNCATE是未知的:
Caused by: org.springframework.data.jpa.repository.query.BadJpqlGrammarException: Line 1:0 mismatched input 'TRUNCATE' expecting {'(', DELETE, FROM, INSERT, SELECT, UPDATE, WITH}; Bad JPQL grammar [TRUNCATE TABLE CLEANUP_ENTITY_1]
at org.springframework.data.jpa.repository.query.BadJpqlGrammarErrorListener.syntaxError(BadJpqlGrammarErrorListener.java:39)
at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:41)
at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:543)
at org.antlr.v4.runtime.DefaultErrorStrategy.reportInputMismatch(DefaultErrorStrategy.java:327)
at org.antlr.v4.runtime.DefaultErrorStrategy.reportError(DefaultErrorStrategy.java:139)
at org.springframework.data.jpa.repository.query.HqlParser.ql_statement(HqlParser.java:348)
at org.springframework.data.jpa.repository.query.HqlParser.start(HqlParser.java:256)
at org.springframework.data.jpa.repository.query.HqlQueryParser.parseQuery(HqlQueryParser.java:53)
at org.springframework.data.jpa.repository.query.HqlQueryParser.parse(HqlQueryParser.java:63)
at org.springframework.data.jpa.repository.query.JpaQueryParserSupport$ParseState.lambda$new$0(JpaQueryParserSupport.java:182)
型
看起来新的Spring解析器特性不能识别原生查询(https://github.com/spring-projects/spring-data-commons/wiki/Spring-Data-2023.0-%28Ullman%29-Release-Notes)。我在我的类路径中有Hibernate Validator。也许这就是问题所在。这是一个bug还是我走错了路?
1条答案
按热度按时间xxe27gdn1#
这似乎是一个已知的Spring Data JPA bug。尝试升级到Sping Boot 3.1.3,如果这没有帮助,那么你可能必须等待这个问题得到修复:
https://github.com/spring-projects/spring-data-jpa/pull/3145