Can anyone see anything wrong with this code

I am not sure what is going on here, but I am not seeing anything wrong with this code.

public any function getCategoriesById(required any event, boolean asQuery=false) {

local.criteria = {

catId = event.getValue(‘catId’,’’)

};

savecontent variable=“local.hqlQuery” {

writeOutput("

FROM category as category

where category.parent=:catId

order by category.left

");

}

return ORMService.executeQuery(query=local.hqlQuery, params = local.criteria, asQuery = arguments.asQuery);

}

I have used this many times in the past any never had any sort of problems, now if I modify the code to the below it actually works

public any function getCategoriesById(required any event, boolean asQuery=false) {

savecontent variable=“local.hqlQuery” {

writeOutput("

FROM category as category

where category.parent=1

order by category.left

");

}

return ORMService.executeQuery(query=local.hqlQuery, asQuery = arguments.asQuery);

}

This has had me stumped for a few hours now and not sure what the problem is. The error is as follows

Application Execution Exception

Error Type: Expression : [N/A]
Error Messages: You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members.

coldfusion.runtime.ScopeCastException: You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members.

at coldfusion.runtime.Cast._Map(Cast.java:1247)

at coldfusion.runtime.Cast._cast(Cast.java:205)

at coldfusion.orm.ORMUtils.getTypedValue(ORMUtils.java:345)

at coldfusion.orm.hibernate.HibernatePersistenceManager.setQueryParams(HibernatePersistenceManager.java:873)

at coldfusion.orm.hibernate.HibernatePersistenceManager._executeHQL(HibernatePersistenceManager.java:791)

at coldfusion.orm.hibernate.HibernatePersistenceManager.executeHQL(HibernatePersistenceManager.java:752)

at coldfusion.orm.hibernate.HibernatePersistenceManager.executeQueryWithNamedParams(HibernatePersistenceManager.java:627)

at coldfusion.orm.ORMUtils._executeQuery(ORMUtils.java:332)

at coldfusion.orm.ORMUtils.executeQuery(ORMUtils.java:320)

at coldfusion.runtime.CFPage.ORMExecuteQuery(CFPage.java:7805)

at cfBaseORMService2ecfc889103823$funcEXECUTEQUERY.runFunction(N:\Projects\ColdFusion\dev.andyscott.id.au\ColdBox\system\orm\hibernate\BaseORMService.cfc:168)

at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)

at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405)

at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)

at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)

at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)

at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:517)

at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:496)

at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:355)

at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2301)

Regards,

Andrew Scott

http://www.andyscott.id.au/

It's early here and I haven't had my coffee yet, but I think the
semi-colon is in the wrong place here:

local.criteria = {
                  catId = event.getValue('catId','')
            };

Judah

Better grab that coffee Judah, all that is doing is saying get the value
catId from the RC if it is not found set the default to an empty value.

If I do a break before the ORMService.executeQuery() the
local.criteria.catId indeed has the correct value. I am beginning to think
this is a ColdFusion bug actually, because I modified it to the following
code which I don't want to do because it then loses the binding and then
opens up for SQL injection.

  public any function getCategoriesById(required any event) {
    savecontent variable="local.hqlQuery" {
      writeOutput("FROM category as category where
category.parent=#event.getValue('catId')# order by category.left");
    }
    return ORMService.executeQuery(query=local.hqlQuery, asQuery
= false);
  }

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Judah McAuley
Sent: Wednesday, 30 March 2011 1:55 AM
To: coldbox@googlegroups.com
Subject: Re: [coldbox:9014] Can anyone see anything wrong with this code

It's early here and I haven't had my coffee yet, but I think the

semi-colon is in

Might be a type issue with hibernate. Try java casting the catID.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

If you mean like using javaCast(‘int’, catId)?

Yeah I did try that and got the same result.

Regards,

Andrew Scott

http://www.andyscott.id.au/

Just out of curiosity, have you tried.

public any function getCategoriesById(required any event, boolean asQuery=false) {

var criteria = {

catId = event.getValue(‘catId’,’’)

};

savecontent variable=“local.hqlQuery” {

writeOutput("

FROM category as category

where category.parent=:catId

order by category.left

");

}

return ORMService.executeQuery(query=local.hqlQuery, params = criteria, asQuery = arguments.asQuery);

}

Curt

Curt no I hadn’t, and I just tried it with no success L

Regards,

Andrew Scott

http://www.andyscott.id.au/