6

我正在使用 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 ....

任何人都知道如何解决这个问题并使用cfqueryparamHQLcfquery查询?

提前致谢!

4

3 回答 3

2

去掉数据类型,它不是必需的,hibernate 可能不理解它们。

于 2010-11-11T21:56:03.463 回答
1

间接答案:改用绑定参数。

<cfset orderDetail = ORMExecuteQuery("from Orders where OrderID=:orderid and ProductID=:productid", {orderid=1, productid=901}, true)>

不过,您仍然必须对变量进行自己的验证。

于 2010-11-11T12:11:05.653 回答
1

我明白了这一点。

我的States对象是这样设置的:

  <cfcomponent output="false" persistent="true">

      <cfproperty name="stateID" type="numeric" fieldType="id" generator="identity" />
      <cfproperty name="name" type="string" />
      <cfproperty name="alphaCode" type="string" />


      <!--- Relationships --->
      <cfproperty name="country" type="array" fieldtype="many-to-one" cfc="Countries" fkcolumn="countryID" lazy="true" />



  </cfcomponent>

使用<cfqueryparam>标签时,Hibernate 可能试图将我作为数组传入的数字映射并失败,从而引发错误。

如果我像这样从属性中删除关系:

<cfproperty name="countryID" type="numeric" />

...然后它的工作原理。

于 2010-11-15T14:21:02.993 回答