Database.transaction

New in package 166

Syntax

Database.transaction( function transactionFunction() {
    ...
    } );

Parameters

Parameter Description
transactionFunction A callback function to execute in a new transaction.

Description

Executes the specified transactionFunction callback in a new transaction.

If an exception is thrown from transactionFunction callback, the transaction is rolled back and any changes to the objects loaded or added within transactionFunction callback are discarded.

Otherwise the following entities are saved and the transaction is committed:

  • modified entities loaded within the transactionFunction callback,
  • entities added to Database repositories within the transactionFunction callback.

Database entities from other scopes cannot be added to Database repositories within transactionFunction callback.

Examples

Creating a new object:

Entities from other scopes cannot be added to Database repositories within transactionFunction callback:

Executing a stored procedure:

Creating objects in batches:

See also

Database, Database.query, Database.scope, Database.executeSql

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.