ColdBox 3.7 - CriteriaBuilder error

Hi folks,

I’m running this on the latest version of Railo, and could have sworn that this ran without issue on ACF.
I have the following CriteriaBuilder query:

any function getLocationsByGeofence(required numeric geofenceid) output=false{
var c = ORMService.newCriteria( “Location” );
c.createAlias( ‘geofence’, ‘geo’ ).isEq( ‘geo.GeoFenceID’, Javacast(“int”, arguments.geofenceid) );
return c.list();
}

When c.list() is called I get the following error:

Error Type: java.lang.ClassCastException : 0
Error Messages: java.lang.Integer cannot be cast to java.lang.Double

This looks to me like a pretty straightforward criteria builder query. If it would help to post the full stacktrace or the models, please let me know.

Thanks for taking a look.

Nolan

Hi Nolan–

Try the new(ish) convertValueToJavaType() method in the BaseORMService. Here’s an example in the test suite: https://github.com/ColdBox/coldbox-platform/blob/master/testing/cases/orm/hibernate/BaseORMServiceTest.cfc

I was able to get this to work by changing “int” to “double”.

geo.GeoFenceID is a bigint in the db.

Not sure if this is a bug, or why ACF would not throw an error on this but Railo would.

Nolan

This gives me an idea. What do you think Joel of adding a new param to the newCriteria() method:

  • autoCast=false

So if you add this:

newCriteria(autoCast=true)

With this we can create the Restrictions object with auto casting for values, what do you think?

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

Yea, I think that would be cool. In looking at the commit, Curt suggested that this might present some overhead. But if it’s opt-in/out, I think that would be a good compromise.

signature0.jpg

Yes, also maybe we can be smarter and track the entity metadata somewhere for optimizations.

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

signature0.jpg

I think it’s a good thing to pursue since questions about this pop up fairly regularly. Plus, the docs need to be updated for Criteria Builder/ Base ORM Service…I’m not sure they currently reflect these additions.

signature0.jpg

signature0.jpg

+1. I like that idea.

Thanks!

Nolan

signature0.jpg

signature0.jpg

Joel, you should have edit permissions on the ColdBox Wiki. Please update the Criteria Builder docs as necessary. :slight_smile:

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

signature0.jpg

signature0.jpg

Actually, I was half-right. There are apparently two versions of the relevant pages, one under “ORM” and one under “Extras”. I’ll make the necessary changes tonight.

Thanks!

signature0.jpg

signature0.jpg

+1, also we should build an internal cache of the metadata, but just lazy load it.

Curt

signature0.jpg

Which one I extras ?

Luis Majano
CEO
Ortus Solutions, Corp
Toll Free/Fax: 1-888-557-8057
Direct: 909-248-3408
www.ortussolutions.com
Twitter: @lmajano, @ortussolutions

1 vote for the autocast. :slight_smile: