这里的语法有什么问题:
@Modifying
@Query(nativeQuery = true, value = "delete from simple_token where simple_token.expiry < NOW()")
int deleteExpiredTokens();
我得到异常
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's where s.expiry < now()' at line 1
但“按原样”执行的查询将在 MYSQL 客户端中正常执行。
我做错了什么?
最佳答案
您声明的查询和语法错误不同。 where s.expiry < now()
在异常(exception)情况下,但simple_token.expiry < NOW()
在@Query
.看起来您运行了错误的查询。可能是别名不正确
关于java - 如何从 Spring @Query 注解调用 SQL 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27795930/