The Hibernate Query Language (HQL) methods return a single or multi-dimensional array of values or entities, based on what the HQL query returns. If you are sure that only one record exists that matches this filter criteria, specify unique=true so that a single entity is returned instead of an array.
If unique=true and multiple records are returned, then an exception is thrown.
Note: entityname and properties used in HQL are case sensitive. |
The following HQL methods are available:
Runs HQL on the default data source specified for the application. You can specify several options to control the behavior of retrieval using queryOptions:
timeout: Specifies the timeout value (in seconds) for the query
Note: Maxresults and timeout are used for pagination. |
<cfset employees = ORMExecuteQuery("from Employees")>
<cfset employees = ORMExecuteQuery("from Employees where age > 40")>
<cfset employeeObj = ORMExecuteQuery("from Employees where EmployeeID =1", true)>
<cfset firstNameArray = ORMExecuteQuery("select FirstName from Employees")>
<cfset numberOfEmps = ORMExecuteQuery("select count(*) from Employees")>
<cfset firstName = ORMExecuteQuery("select FirstName from Employees where EmployeeID = 1", true)>
<cfset employees = ORMExecuteQuery("from Employees", false, {offset=5, maxresults=10, timeout=5})>
ORMExecuteQuery(hql, params [,unique] [,queryOptions])
This type of ORMExecuteQuery lets you pass parameters to the query. Use '?' (question mark) as the placeholder for the parameters. The values to the parameters must be passed as an array to params.In addition, you can specify several options to control the behavior of retrieval using queryOptions:
timeout: Specifies the timeout value (in seconds) for the query
Note: Maxresults and timeout are used for pagination. |
<cfset employees = ORMExecuteQuery("from Employee where age > ?", [40])>
<cfset employeeObj = ORMExecuteQuery("from Employee where EmployeeID=?", [1], true)>
<cfset employees = ORMExecuteQuery("from Employee where age > ? and age < ?", [40, 80])>
ORMExecuteQuery(hql, namedparams [, unique] [, queryOptions])
This type of ORMExecuteQuery lets you pass named parameters to the query. The placeholder for the parameter must be a name and must start with ":" as in ":age" or ":id". The values to the names must be passed as key-value pairs.In addition, you can specify several options to control the behavior of retrieval using queryOptions:
timeout: Specifies the timeout value (in seconds) for the query
Note: Maxresults and timeout are used for pagination. |
To retrieve employee details of all employees whose reside in USA and are also citizens of USA:
<cfset USEmployees = ORMExecuteQuery("from Employee where country=:country and
citizenship=:country", {country='USA'})>
<cfset orderDetail = ORMExecuteQuery("from Orders where OrderID=:orderid and
ProductID=:productid", {orderid=1, productid=901}, true)>
Sign in to your account