# ORMExecuteQuery()

Runs the HQL on the default data source specified for the application.

**Requires Extension:** [Hibernate ORM Engine Extension](https://download.lucee.org/#FAD1E8CB-4F45-4184-86359145767C29DE)

```
ORMExecuteQuery( hql=string, paramsOrUnique=any, uniqueOrQueryOptions=any, queryOptions=any );
```

**Returns:** any

# Arguments

| Argument | Type | Required | Description | Default |
|----------|------|----------|-------------|---------|
| hql | string | Yes | The hql query to execute |  |
| paramsOrUnique | any | No | Object parameter for the entity *Alias: params* |  |
| uniqueOrQueryOptions | any | No | Specifies if the object parameter is unique *Alias: unique* |  |
| queryOptions | any | No | Options for the query |  |

# Usage Notes

Executes an HQL (Hibernate Query Language) query. HQL operates on entity names and property names, not table and column names.

The function signature is flexible:

- `ORMExecuteQuery( hql )` — no params, returns array
- `ORMExecuteQuery( hql, params )` — params as struct (named) or array (positional)
- `ORMExecuteQuery( hql, unique )` — no params, returns single entity if `true`
- `ORMExecuteQuery( hql, params, unique )` — with params, returns single entity if `true`
- `ORMExecuteQuery( hql, params, unique, options )` — full form with query options

The `options` struct supports: `maxresults`, `offset`, `cacheable`, `cachename`, `timeout`, `datasource`.

`ORMQueryExecute()` is an alias for this function.

For bulk UPDATE/DELETE via HQL, entity lifecycle events do **not** fire. See [ORM - Querying](../../recipes/orm-querying.md) for full documentation.

# Examples

```cfml
// Named parameters
users = ORMExecuteQuery(
	"FROM User WHERE status = :status",
	{ status: "active" }
);

// Positional parameters
users = ORMExecuteQuery(
	"FROM User WHERE name = ?1",
	[ "Susi" ]
);

// Single result
user = ORMExecuteQuery(
	"FROM User WHERE email = :email",
	{ email: "susi@example.com" },
	true
);

// Pagination
page = ORMExecuteQuery(
	"FROM User ORDER BY name",
	{},
	false,
	{ maxresults: 10, offset: 20 }
);

// IN clause with array
users = ORMExecuteQuery(
	"FROM User WHERE role IN (:roles)",
	{ roles: [ "admin", "editor" ] }
);

// Aggregate
total = ORMExecuteQuery( "select count(u) from User u", {}, true );

// Bulk update (no entity events fired)
ORMExecuteQuery(
	"UPDATE User SET status = :status WHERE lastLogin < :cutoff",
	{ status: "inactive", cutoff: dateAdd( "m", -6, now() ) }
);
```







# Categories

[ORM](../../categories/orm.md)

# See Also

[ORMQueryExecute()](ormqueryexecute.md), [ORM - Querying](../../recipes/orm-querying.md)