Using cfqueryparam with ColdFusion HQL query

I use the HQL query to get a bunch of state objects, for example:

<cfquery name="LOCAL.qStates" dbtype="hql">
    from States where countryID = #ARGUMENTS.countryID#
    order by name asc
</cfquery>

It works great. However, I was well brought up, and I want to use cfqueryparam, ideally, this:

<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 causes 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 ....

Does anyone know how to get around this and use cfqueryparamwith cfqueryHQL queries?

Thanks in advance!

+5
source share
3 answers

I got to the end.

My object Stateswas configured as follows:

  <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" />

... .

+1

, , , , .

+2

Indirect answer: Use related parameters instead.

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

However, you will still have to collapse your own variable check.

0
source

All Articles