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