← Back to Stormify Documentation

transaction

fun <R> transaction(block: () -> R): R

Executes block within a database transaction with automatic commit on success and rollback on any thrown exception, returning the block's result.

Nesting. If this call is made from inside another transaction { } on the same Stormify instance and the same thread (detected via ActiveTxRegistry), the inner call reuses the outer connection and bounds its work with a database savepoint — so a failure inside the nested block rolls back only its work, not the outer transaction. There is no syntactic distinction: the same call is a top-level tx when there is no ambient one, and a savepoint otherwise.

Ambient connection. While the block runs, all convenience operations on this instance (including create/read/update/delete/findById/…, top-level extensions, lazy-loading delegates, PagedList, etc.) transparently route through this transaction's connection — you do not need to thread a context parameter through your code.