IsWithinORMTransaction()

edit

Returns true if a Hibernate ORM transaction is currently active on any ORM datasource. Safe to call when ORM is not configured — returns false.

Requires Extension: Hibernate ORM Engine Extension

IsWithinORMTransaction( );

Returns: Boolean

true if a Hibernate transaction is active, false otherwise.

This function does not take any arguments.

Usage Notes

edit

New in 5.6. Replaces the need for Java hacks like ACF's TransactionTag.getCurrent() reflection pattern.

Safe to call at any time — returns false if ORM is not enabled or no transaction is active.

See ORM - Sessions and Transactions for transaction details.

Examples

edit
// Outside any transaction
isWithinORMTransaction(); // false

transaction { isWithinORMTransaction(); // true entitySave( entityNew( "User", { name: "Susi" } ) ); }
isWithinORMTransaction(); // false

See also