[coldbox-5.2.0+791] findBy error

What am I doing wrong here? I have:

ORMService.findByAFieldAndAnotherField( ‘text’, 1 )

…and that’s producing:

Can’t cast Object type [Number] to a value of type [Component]Java type of the object is java.lang.Double Dynamic compiled query: {UNIQUE={true}, OPTIONS={{datasource={mydatasource}}}, PARAMS={{param1={text}, param2={1}}}, ISCOUNTING={false}, HQL={from MyModel where AField = :param1 and AnotherField = :param2}, METHOD={AFieldAndAnotherField}}

Hi John,

try this ORMService.findByAFieldAndAnotherField( ‘text’, javacast(‘int’, 1) ).

That may or may not work. I know there is a problem with adobe2016 and below with how primitives are stored in the background. (http://wwvv.codersrevolution.com/blog/why-is-lucee-so-much-better-at-handling-json)

Same error but now it reads, “Can’t cast Object type [Number] to a value of type [Component]Java type of the object is java.lang.Integer

Oh, and I’m using Lucee.

In your example ORMService.findByAFieldAndAnotherField( ‘text’, 1 )

are you sure AField and AnotherField are properties with a primitive datatype? (ie, not a cfc or relationship)

Oh, well, AnotherField is:

property name=“AnotherField” ormtype=“integer” fieldtype=“many-to-one” cfc=“AnotherModel” fkcolumn=“AnotherField”;

Is that the problem?

What does your entity look like

Luis Majano
CEO
Ortus Solutions, Corp

P/F: 1-888-557-8057

– -- – You received this message because you are subscribed to the Google Groups “ColdBox Platform” group. For News, visit For Documentation, visit For Bug Reports, visit — You received this message because you are subscribed to the Google Groups “ColdBox Platform” group. To unsubscribe from this group and stop receiving emails from it, send an email to . To post to this group, send email to . To view this discussion on the web visit . For more options, visit .

Yes that makes no sense. Hmthat is a relationship which expects an entity not an integer. You have modeled the relationship incorrectly.

Luis Majano
CEO
Ortus Solutions, Corp

P/F: 1-888-557-8057

– -- – You received this message because you are subscribed to the Google Groups “ColdBox Platform” group. For News, visit For Documentation, visit For Bug Reports, visit — You received this message because you are subscribed to the Google Groups “ColdBox Platform” group. To unsubscribe from this group and stop receiving emails from it, send an email to . To post to this group, send email to . To view this discussion on the web visit . For more options, visit .

In the database, it’s a foreign key. As it currently is, it seems to work fine for CRUD (except for that issue we identified where the select box is not rendered on “new,” only on “edit”).

How should it look in my model?

Your definition is not totally correct:

property name=“relatedContent”
notnull=“true”
cfc=“contentbox.models.content.BaseContent”
fieldtype=“many-to-one”
fkcolumn=“FK_contentID”
lazy=“true”
index=“idx_contentComment”;

Here is an example

Also, you are passing an integer to the finder, which the cborm module WON’T magically convert it to the entity. So if that’s an entity, then pass an entity.

ORMService.findByAFieldAndAnotherField( ‘text’, service.get( 1 ) )

So if that’s an entity, then pass an entity.

OK, so I’d do something like this…?

ORMService.findByAFieldAndAnotherField( ‘text’, AnotherField.get(1) )

I’m still having trouble with this. I’m trying:

thisAF = AnotherField.get(1);

ORMService.findByAnotherFieldAndAField( thisAF, ‘text’ )

And it’s giving me:

Type: BaseORMService.HQLQueryException
Messages: Not all named parameters have been set: [param1] [from MyObject where AnotherField = :param1 and AField = :param2]

This despite the fact that thisAF definitely does have the correct object in there. Help?

John,

Without any code it is really hard to digest this.

How about moving to criteria based queries instead? Have you tried it

newCriteria()
.eq( “AField”, value )
.eq( “AnotherField”, value )
.get();

Without making any changes to the model, that worked perfectly. Apparently, under the hood, those two syntaxes are meaningfully different.

Thanks!