Bx-orm: a numeric ID passed as a string fails with "String cannot be cast to Integer" (Adobe ColdFusion and Lucee convert it)

Versions

  • BoxLang 1.18.0+66, bx-orm 1.7.3-snapshot (Nov 1, with BLMODULES-306), bx-compat-cfml 1.40.0+56, MariaDB 12.3

What happens

When an integer property or HQL parameter gets its value as a string, for example "1" from a form, a URL or a type="string" argument, bx-orm passes the string to Hibernate, which fails:


class java.lang.String cannot be cast to class java.lang.Integer

Adobe ColdFusion and Lucee convert the string to the property’s type, so this code works there.

Reproduction (entity Users with <cfproperty name="UserId" fieldtype="id" generator="native">):


<cfset id = "1">

<!--- 1. entityLoad with a filter: fails --->

<cfset u = entityLoad("Users", { UserId = id }, true)>

<!--- 2. ormExecuteQuery with a named parameter: fails --->

<cfset r = ormExecuteQuery("FROM Users WHERE UserId = :id", { id = id })>

<!--- 3. HQL cfquery with cfqueryparam and no cfsqltype: fails --->

<cfquery name="q" dbtype="hql">

SELECT u.UserId FROM Users u WHERE u.UserId = <cfqueryparam value="#id#">

</cfquery>

What works on BoxLang (for comparison):

| Call | Result |

|—|—|

| entityLoad("Users", { UserId = 1 }, true) (a number) | works |

| entityLoadByPK("Users", "1") (a string) | works |

| <cfqueryparam value="#id#" cfsqltype="integer"> (or cf_sql_integer) | works |

| the three calls above, with id = "1" | fail |

So entityLoadByPK() and typed cfqueryparam already convert; filters in entityLoad(), named and positional parameters in ormExecuteQuery(), and untyped cfqueryparam in HQL don’t.

Why it matters

CFML code passes IDs as strings all the time, because form and URL values are strings. In the application I’m testing there are about 58 entityLoad filters and 35 untyped HQL cfqueryparams that can get one. With BLMODULES-306 the installer now completes on BoxLang, and this is what stops the home page and the Privacy page next.

Request

Could bx-orm convert a parameter or filter value to the mapped property’s type (as Hibernate’s own setParameter with a type, or as entityLoadByPK already does), at least when bx-compat-cfml is installed?

Thanks again for the very quick fix on BLMODULES-306.