Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate公式注释-MySql函数:间隔,天_Java_Mysql_Hibernate_Annotations - Fatal编程技术网

Java Hibernate公式注释-MySql函数:间隔,天

Java Hibernate公式注释-MySql函数:间隔,天,java,mysql,hibernate,annotations,Java,Mysql,Hibernate,Annotations,我有密码: @Id @Column(name = "id") @GeneratedValue private int id; @Formula(value = "(SELECT count(history.city_id) FROM history where history.ts > (now() - INTERVAL 30 DAY) and history.city_id = id)") private int last30daysUpdates; 因此,Hibernate将此公式

我有密码:

@Id
@Column(name = "id")
@GeneratedValue
private int id;

@Formula(value = "(SELECT count(history.city_id) FROM history where history.ts > (now() - INTERVAL 30 DAY) and history.city_id = id)")
private int last30daysUpdates;
因此,Hibernate将此公式解析为:

 ...where
            history.ts > (
                now() - entitycity0_.INTERVAL 30 entitycity0_.DAY
            ) ...
错误是:

您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以了解在“30 entitycity0_uu0.DAY”附近使用的正确语法

我怎么能说hibernate的间隔和日期是MysqL的功能呢?可能吗


谢谢。

INTREVAL
DAY
(此处使用)不是函数。不确定Hibernate是否被“说服”,但您可以尝试替换:

(now() - INTERVAL 30 DAY)
与:


INTREVAL
DAY
(此处使用)不是函数。不确定Hibernate是否被“说服”,但您可以尝试替换:

(now() - INTERVAL 30 DAY)
与:


您使用哪种MySQL方言? 如果使用mysqldialent或mysql5dialent,则可以使用以下命令:

SELECT count(history.city_id) FROM history where timediff(now(), history.ts) < '720' and history.city_id = id
查询:

History.ts < date_sub_interval(now(), 30, DAY)
History.ts
您使用哪种MySQL方言? 如果使用mysqldialent或mysql5dialent,则可以使用以下命令:

SELECT count(history.city_id) FROM history where timediff(now(), history.ts) < '720' and history.city_id = id
查询:

History.ts < date_sub_interval(now(), 30, DAY)
History.ts
DATE\u SUB(NOW(),entitycity0\u.INTERVAL 30 entitycity0\u.DAY)DATE\u SUB(NOW(),entitycity0\u.INTERVAL 30 entitycity0\u.DAY)我使用org.hibernate.dialen.mysqlinnodbdialent你可以使用JPA nativeQueryI使用org.hibernate.dialent.mysqlinnodbdialent你可以使用JPA nativeQuery