[coldbox-3.5.3] [wirebox] FindAllWhere attempt to dereference scalar.

I’m attempt to get orm search functionality working in an app that I’m building and can’t figure out how to get this to work.
An entity is connected to other entities through the comp_id which is an number in the database. rc.comp_id shows up as a number in the debugger output.

When I try to find the connected entities I get the following error.
You have attempted to dereference a scalar variable of type class java.lang.Integer as a structure with members.

I’ve tried all of the following and still get the same error on the lines prc.photos =

var c = StructNew();

StructInsert( c, “comp_id”, event.getValue( “comp_id” ) );

prc.photos = getModel(“photoService”).findAllWhere( criteria=c );

Here are my models:

component entityName=“comparable” persistent=“true” extends=“coldbox.system.orm.hibernate.ActiveEntity” … {

property name=“comp_id” column=“compid” fieldtype=“id” generator=“sequence” sequence="…";

}

component entityName=“photo” persistent=“true” extends=“coldbox.system.orm.hibernate.ActiveEntity” … {

property name=“photo_id” fieldtype=“id” column=“photo_id” generator=“sequence” sequence="…" setter=“false”;

property name=“comp_id”

}

component extends=“coldbox.system.orm.hibernate.VirtualEntityService” singleton{

photoService function init(){

super.init(entityName=“photo”);

return this;

}

}

Thanks,
Aaron

Need a stacktrace on this.

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:1260)
	at coldfusion.runtime.Cast._cast(Cast.java:204)
	at coldfusion.orm.ORMUtils.getTypedValue(ORMUtils.java:359)
	at coldfusion.orm.hibernate.CriteriaBuilder.addField(CriteriaBuilder.java:67)
	at coldfusion.orm.hibernate.CriteriaBuilder.addFields(CriteriaBuilder.java:57)
	at coldfusion.orm.hibernate.HibernatePersistenceManager.load(HibernatePersistenceManager.java:382)
	at coldfusion.orm.hibernate.HibernatePersistenceManager.load(HibernatePersistenceManager.java:354)
	at coldfusion.orm.ORMUtils.entityLoad(ORMUtils.java:169)
	at coldfusion.runtime.CFPage.EntityLoad(CFPage.java:8846)
	at cfBaseORMService2ecfc2060280445$funcFINDALLWHERE.runFunction(C:\ColdFusion10\cfusion\wwwroot\shared\coldbox\system\orm\hibernate\BaseORMService.cfc:315)
	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:220)
	at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:2659)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2455)
	at cfVirtualEntityService2ecfc1199881739$funcFINDALLWHERE.runFunction(C:\ColdFusion10\cfusion\wwwroot\coldbox\system\orm\hibernate\VirtualEntityService.cfc:109)
	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:518)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:660)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:469)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2373)
	at cfcomparables2ecfc1295724550$funcVIEW.runFunction(C:\ColdFusion10\cfusion\wwwroot\mlw\app2\handlers\comparables.cfc:290)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
	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:518)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:660)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:469)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2373)
	at coldfusion.tagext.lang.InvokeTag.doEndTag(InvokeTag.java:402)
	at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2800)
	at cfController2ecfc578711246$funcINVOKER.runFunction(C:\ColdFusion10\cfusion\wwwroot\shared\coldbox\system\web\Controller.cfc:753)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
	at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
	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:220)
	at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:2659)
	at cfController2ecfc578711246$funcRUNEVENT.runFunction(C:\ColdFusion10\cfusion\wwwroot\shared\coldbox\system\web\Controller.cfc:637)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
	at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
	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:518)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:660)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:469)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2373)
	at cfColdbox2ecfc1673182520$funcPROCESSCOLDBOXREQUEST.runFunction(C:\ColdFusion10\cfusion\wwwroot\coldbox\system\Coldbox.cfc:236)
	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:220)
	at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:2659)
	at cfApplication2ecfc1765025586$funcONREQUESTSTART.runFunction(C:\ColdFusion10\cfusion\wwwroot\mlw\app2\Application.cfc:55)
	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:220)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:655)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:444)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:414)
	at coldfusion.runtime.AppEventInvoker.invoke(AppEventInvoker.java:108)
	at coldfusion.runtime.AppEventInvoker.onRequestStart(AppEventInvoker.java:278)
	at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:411)
	at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
	at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
	at coldfusion.filter.PathFilter.invoke(PathFilter.java:112)
	at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30)
	at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94)
	at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
	at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
	at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
	at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
	at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
	at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
	at coldfusion.CfmServlet.service(CfmServlet.java:219)
	at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
	at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:414)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:662)

The following unit test works just fine.

component extends=“coldbox.system.testing.BaseModelTest” model=“mlw.app2.model.photoService”{
void function setup(){
super.setup(entityName=“photo”);
// init the model object
model.init();
}
void function findAllWhere() {
var r = model.findAllWhere( criteria={comp_id=16486} );
assertIsArray( r );
assertEquals( “5”, ArrayLen( r ), ‘r should contain 5 values.’);
}
}

@AW

If comp_id in your Photo entity is a relationship to comp_id in Comparable, I believe you’ll need to make the value in your filtercriteria structure to be the actual Comparable instance you want to use as criteria, and not just the id of the Comparable.

Let’s say I have this example:

component table=“Car” persistent=true {
property name=“CarID” fieldtype=“id” …;
}
component table=“Insured” persistent=true {
property name=“InsuredID” fieldtype=“id”…
property name=“CarID” fieldtype=“many-to-one”…
}

If I do the following, I get the same error that you posted:

var c = structNew();
StructInsert( c, “CarID”, 2 );
var result = getModel( “Insured” ).findAllWhere( criteria=c )

However, if I modify it as follows, I get the results I expect:

Joel is right. You can also use criteria queries so you don’t have to load anything and just traverse the relationship to any property in it.

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

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

Social: twitter.com/lmajano facebook.com/lmajano

+1 for criteria queries :slight_smile:

signature0.jpg

Thank you guys for the help. I believe I understand the orm concept but getting to work has been frustrating. When I look at the dump of a photo I see the comp that it is connected with but not the other way around.

Thanks Luis (and team) for all the examples you have posted on the site. (http://blog.coldbox.org/blog/hql-query-to-criteria-query-example)

Here is what I ended up getting to work since I since I had previously loaded the comp entity that I was looking for.

var photos = getModel(“photoService”);
var c = photos.newCriteria();
prc.photos = c.eq(‘comp_id’, prc.comp ).list();

I’m still wondering why the unit test worked while the application failed?

Aaron