ORMGetSession()

edit

Returns the current ORM session

Requires Extension: Hibernate ORM Engine Extension

ORMGetSession( datasource=string );

Returns: object

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

edit

Returns the native org.hibernate.Session object for the current request. Lucee returns the Hibernate session directly — unlike ACF which wraps it in coldfusion.orm.hibernate.SessionWrapper.

If you're migrating from ACF code that calls .getActualSession(), remove that call on Lucee.

Do not assign the result to a variable named session — that is a reserved scope in CFML. Use ormSess, hibernateSession, or similar.

The session is created lazily on first ORM operation and closed at the end of the request.

See ORM - Sessions and Transactions for session lifecycle details.

Examples

edit
// Get the native Hibernate session
ormSess = ORMGetSession();
// Check for pending changes
if ( ormSess.isDirty() )
	systemOutput( "Session has unflushed changes", true );
// Check if a loaded entity is still in the session
user = entityLoadByPK( "User", 42 );
systemOutput( ormSess.contains( user ), true ); // true
// Get session statistics
stats = ormSess.getStatistics();
systemOutput( "Entities in session: #stats.getEntityCount()#", true );
// Get an entity's primary key dynamically
pk = ormSess.getIdentifier( user );

See also