What's New in 1.7.3
What's new in bx-orm 1.7.3, HQL through the query component and typed values from forms and URLs
bx-orm 1.7.3 is a fix release for the 1.x line (Hibernate 5). It lets the query component and queryExecute() run HQL, and stops typed properties from failing when their value arrives as a string, such as an id from a form or a URL. There are no breaking changes. Update the module and your code keeps working.
box install bx-orm@1.7.3HQL in the Query Component and queryExecute()
<bx:query> (<cfquery> in CFML templates) and queryExecute() now run HQL when you set dbtype="hql". They return the same result as ORMExecuteQuery: an array of entities, or an array of rows for a projection. Before 1.7.3 the dbtype was ignored, so the HQL ran as SQL against the default datasource and returned a query or a SQL error.
<bx:query name="toyotas" dbtype="hql">
FROM Auto WHERE make = <bx:queryparam value="#form.make#" sqltype="varchar">
</bx:query>var toyotas = queryExecute(
"FROM Auto WHERE make = :make",
{ make: "Toyota" },
{ dbtype: "hql" }
);<bx:queryparam>(<cfqueryparam>) in the body binds a positional parameter. With asqltype(cfsqltype) the value is cast first, andlist="true"binds a list forIN ( ... ).paramsbinds named (struct) or positional (array) parameters, as inORMExecuteQuery().ormoptionstakes theORMExecuteQuery()options, such asmaxResults,offset,readOnlyandunique.maxrows,timeoutanddatasourceapply too.resultgets a struct withsql(the HQL),recordCount,executionTimeandcached.
Without dbtype="hql", both run SQL exactly as before. See HQL in the Query Component.
Typed Values from Forms and URLs
Form and URL values are always strings, and BoxLang arithmetic produces decimals. Before 1.7.3, binding one of them to a typed property failed, because Hibernate 5 binds values as they are:
bx-orm now converts each value to the property's mapped type before Hibernate binds it, so this code works:
The conversion covers entityLoad() filters and every HQL parameter: ORMExecuteQuery(), dbtype="hql" queries, untyped <bx:queryparam> and list parameters.
Whole numbers (integer, long, short, biginteger)
Numbers and numeric strings with no fractional part: "1", " 1 ", "1.0", 1.0
Decimals (double, float, bigdecimal)
Numbers and numeric strings: "2.5"
boolean
Booleans, numbers and boolean strings: "true", "yes", 0
string
Numbers and booleans
A value that does not fit the type is passed to Hibernate unchanged and fails as before. For example, "1.5" is never truncated to 1 for an integer property, and "abc" still fails. entityLoadByPK() and a <bx:queryparam> with a sqltype already converted their values and work as before.
Also in 1.7
If you are coming from an earlier 1.x release, these arrived earlier in the 1.7 line:
1.7.2:
value collections with
fieldtype="collection"(arrays and structs of simple values in their own table);ORM observability events (
onORMQuery,onORMFlush,onORMException) and Hibernate statistics. See Observability.
1.7.1:
entityToQuery()no longer adds always-nullcolumns for relationship properties. See Entities as Queries.1.7.0:
raw Hibernate properties through
hibernatePropertiesandormConfig. See Custom Hibernate Config;SQLite support;
the
uuid2generator.
The full list is in the 1.x release notes.
Last updated
Was this helpful?