gpt4 book ai didi

java - 如何从 Spring @Query 注解调用 SQL 函数

转载 作者:行者123 更新时间:2023-11-30 22:52:21 25 4
gpt4 key购买 nike

这里的语法有什么问题:

@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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com