将 cfqueryparam 与 ColdFusion HQL 查询结合使用
我正在使用 HQL 查询来获取一堆状态对象,如下所示:
<cfquery name="LOCAL.qStates" dbtype="hql">
from States where countryID = #ARGUMENTS.countryID#
order by name asc
</cfquery>
这工作正常。然而,我成长得很好,我想使用 cfqueryparam ,理想情况下是这样的:
<cfquery name="LOCAL.qStates" dbtype="hql">
from States
where countryID = <cfqueryparam cfsqltype="cf_sql_integer" value="#ARGUMENTS.countryID#" />
order by name asc
</cfquery>
但这会引发错误:
[empty string] java.lang.NullPointerException at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:353) at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:323) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:98) at coldfusion.orm.hibernate.HibernatePersistenceManager._executeHQL(HibernatePersistenceManager.java:822) at coldfusion.orm.hibernate.HibernatePersistenceManager.executeHQL(HibernatePersistenceManager.java:751) at ....
任何人都知道如何解决这个问题并将 cfqueryparam 与 < code>cfquery HQL 查询?
提前致谢!
I am using a HQL query to get a bunch of state objects like so:
<cfquery name="LOCAL.qStates" dbtype="hql">
from States where countryID = #ARGUMENTS.countryID#
order by name asc
</cfquery>
This works fine. However, I was brought up well and I want to use cfqueryparam
, ideally like so:
<cfquery name="LOCAL.qStates" dbtype="hql">
from States
where countryID = <cfqueryparam cfsqltype="cf_sql_integer" value="#ARGUMENTS.countryID#" />
order by name asc
</cfquery>
But this throws an error:
[empty string] java.lang.NullPointerException at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:353) at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:323) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:98) at coldfusion.orm.hibernate.HibernatePersistenceManager._executeHQL(HibernatePersistenceManager.java:822) at coldfusion.orm.hibernate.HibernatePersistenceManager.executeHQL(HibernatePersistenceManager.java:751) at ....
Anyone know how to get around this and use cfqueryparam
with cfquery
HQL queries?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
去掉数据类型,它不是必需的,并且休眠可能不理解它们。
Take off the Datatype, it's not required and hibernate probably does not understand them.
间接答案:使用绑定参数代替。
不过,您仍然必须对变量进行自己的验证。
Indirect answer: use bound parameters instead.
You'll have to still roll your own validation on the variables though.
我已经查到这件事的真相了。
我的 States 对象的设置如下:
当使用
标记时,Hibernate 可能试图映射我作为数组传入的数字,但失败,因此抛出错误。如果我像这样从属性中删除关系:
...那么它就有效。
I got to the bottom of this.
My
States
object was setup like so:When using the
<cfqueryparam>
tag Hibernate was perhaps trying to map the number I was passing in as an array and failing thus throwing an error.If I remove the relationship from the property like so:
...then it works.