[Colbox 5.0.0] - CBORM Criteria Query Struggles


I am trying to use coldbox and the cborm module and for the most part, the basic stuff works fine, but I’m trying to figure out how to do a group by query to count the number of jobs in a given city with a max of 4 records returned.

The query/result should return the job id (jobId), name of the city(jobCity), and a count of how many jobs in that city. I can do this with straight cfquery, but trying to do it the cborm way. Here is my code from my handler

property name=“jService” inject=“entityService:Job”;

prc.jobResults = jService.newCriteria().withProjections(groupProperty=“jobCity”,count=“jobCity”).list(max=“4”);

What I am getting is a nested array (shown in my screenshot here) though back which makes it a bit less intuitive to work within my display page where I want to output this data. Any idea how to return this maybe as query with column names? I tried using the “asQuery=true”, but it would not let me return the data in that way.

Any help appreciated… and thanks as always!


You need to use the asStruct() operator. Because natively hibernate just returns the values in a arraylist. So make sure you use the asStruct() in order to tell cborm to convert it to an array of structs.

I did try that, but I get this error Luis:

The asStruct method was not found. Either there are no methods with the specified method name and argument types or the asStruct method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.

prc.jobResults = jService.newCriteria().withProjections(groupProperty=“jobCity”,count=“jobCity”).asStruct().list(max=“4”);

My code:

Which version of CBORM are you using? That method was added to criteria’s queries in in 2.0

Are you on cborm 2.x?

Yup, that was the issue. I was on an older version. I have updated to the latest version of cborm so that should help however a new error is now showing that must be related to the ugprade because I am now getting this:

Error while executing the Hibernate query. org.hibernate.HibernateException: coldfusion.runtime.UndefinedElementException: Element ENTITYNAME is undefined in ARGS.

This error is showing on a line of code that definitely worked with the prior version so I may need to dig into what changed between cborm versions.