I have the code:
@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;
so, hiberante parse this formula to:
...where
history.ts > (
now() - entitycity0_.INTERVAL 30 entitycity0_.DAY
) ...
and the error is:
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 ’30 entitycity0_.DAY)
How can i say hibernate that INTERVAL and DAY are the functions of MysqL? Is it possible?
Thanks.
Which MySQL dialect are you use?
If MySqlDialect oder MySql5Dialect you can use follows:
Or define new hibernate function
Query: