Cia*_*her 6 coldfusion hibernate hql cfquery
我正在使用HQL查询来获取一堆状态对象,如下所示:
<cfquery name="LOCAL.qStates" dbtype="hql">
from States where countryID = #ARGUMENTS.countryID#
order by name asc
</cfquery>
Run Code Online (Sandbox Code Playgroud)
这很好用.但是,我很好,我想使用cfqueryparam,理想情况如下:
<cfquery name="LOCAL.qStates" dbtype="hql">
from States
where countryID = <cfqueryparam cfsqltype="cf_sql_integer" value="#ARGUMENTS.countryID#" />
order by name asc
</cfquery>
Run Code Online (Sandbox Code Playgroud)
但这会引发错误:
[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 ....
Run Code Online (Sandbox Code Playgroud)
任何人都知道如何解决这个问题,并使用cfqueryparam与cfqueryHQL查询?
提前致谢!
我已经查清了这件事的真相。
我的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>
Run Code Online (Sandbox Code Playgroud)
当使用<cfqueryparam>标签时,Hibernate 可能试图映射我作为数组传入的数字,但失败,从而引发错误。
如果我像这样从属性中删除关系:
<cfproperty name="countryID" type="numeric" />
Run Code Online (Sandbox Code Playgroud)
...然后就可以了。