ORMClearSession()
Removes all the entities that are loaded or created in the session. This clears the first level cache and removes the objects that are not yet saved to the database.
Requires Extension: Hibernate ORM Engine Extension
ORMClearSession( datasource=string );
Returns: void
| Argument | Description |
|---|---|
|
datasource
string,
optional
|
edit
datasource used for the session, if nor defined the datasource defined in application.cfc/cfapplication is used. |
Usage Notes
editUnflushed changes are lost. This function clears the first-level session cache without flushing — all entities become detached and any pending INSERT/UPDATE/DELETE operations are discarded.
If you need to persist changes before clearing, call ORMFlush() first.
Common uses:
- Ensuring fresh database reads (e.g. after bulk SQL updates)
- Releasing memory in long-running requests that load many entities
- Testing: clearing state between operations
See ORM - Sessions and Transactions for entity lifecycle states.
Examples
edit// Flush first, then clear
ormFlush();
ormClearSession();
// Now entityLoadByPK will hit the database, not the session cache
freshUser = entityLoadByPK( "User", 42 );
// Clear a specific datasource session
ormClearSession( "inventoryDB" );
See also
- ORM
- ORM - Sessions and Transactions
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)