return sessionFactory.getCurrentSession().
createQuery("FROM Weather WHERE city_id = :id AND date " +
"BETWEEN now()::date AND now()::date + (:days - 1)").
setInteger("id", city_id).setString("days", days).list();
getting error:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: :
How can I use this syntax in HQL?
Basically the problem is that I want to use colon(:) in my query, but when hibernate sees colon, it thinks that it is a paramter(:parameterName is syntax for parameters in HQL), as you can see from my 2 uses(:id and :days
).
But when I am using now()::date statement, it is specific postgreSQL syntax, hibernate ruins everything.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…