@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, Hibernate converts this string to:
...where history.ts > ( now() - entitycity0_.INTERVAL 30 entitycity0_.DAY ) ...
And the error:
You have an error in your SQL syntax; check my server for the right syntax to use near '30 entitycity0_.DAY)
How to make it clear to Hiber that INTERVAL and DAY are mysql functions? Maybe? Thank.