Hibernate查询参数绑定引发QuerySyntaxException。

huangapple go评论52阅读模式
英文:

HIbernate query parameter binding throws QuerySyntaxException

问题

我有这个HQL查询:

... DATE_ADD(p.bar.foo,INTERVAL :param SECOND) < NOW() ...

Hibernate抛出了这个异常:

org.hibernate.hql.ast.QuerySyntaxException:意外的标记:: 位于第1行,第715列

Hibernate说语法异常与:param有关。

我想做的只是在非HQL表达式中绑定参数。

英文:

I have this hql query :

... DATE_ADD(p.bar.foo, INTERVAL :param SECOND) < NOW() ...

Hibernate throws this exception :

org.hibernate.hql.ast.QuerySyntaxException: unexpected token: : near line 1, column 715

Hibernate says that the syntax exception is related to :param.

What i wanted to do is just to bind param in a none hql experssion.

答案1

得分: 1

Hibernate HQL没有INTERVAL关键字。
您可以尝试使用Criteria,通过Restrictions.sqlRestriction()使用本机SQL。

链接:https://fmdojo.wordpress.com/2014/05/14/native-sql-inside-criteria-hibernate/

英文:

Hibernate HQL doesn't have INTERVAL.
You can try to use Criteria with native SQL using Restrictions.sqlRestriction()

https://fmdojo.wordpress.com/2014/05/14/native-sql-inside-criteria-hibernate/

huangapple
  • 本文由 发表于 2020年9月5日 06:37:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/63748752.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定