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();
得到错误:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: :
如何在HQL中使用这种语法?
基本上问题是我想在我的查询中使用冒号(:),但是当hibernate看到冒号时,它认为它是一个参数(:parameterName是HQL中的参数的语法),你可以从我的2个使用:id和:days)。
但是当我使用now():: date语句时,它是具体的postgreSQL语法,hibernate会废除一切。