Previous Topic

Book Contents

Book Index

Next Topic

Registering Objects to Transactions

When you create a new business object, it is normally registered to a particular transaction immediately. But what if there is a need to create a business object without registering it to a transaction at that time – or even, without registering it at all? There are various reasons, which might make you do so.

To begin with, most objects have so called constraints, which specify, for example, that certain attributes must be set before saving the object to the database. These constraints should be checked before committing the transaction, because if you attempt to create an object without setting those attributes first, the operation will result in an exception on the commit. Therefore, it might be very useful, for example in workflows, to create an object first outside the transaction and register it to a transaction only after you have successfully tested that the user has filled out all the necessary attributes etc. Otherwise, the transaction would be depreciated by holding such inconsistent object and could not be committed anymore. The other situation in which you should avoid registering objects to the transaction is, when you work with so called transient objects, which can never be created in transactions (see Creating Transient Objects).

  • Registering newly created objects

To register a newly created object that has not been previously registered to a transaction, call

ApiTransaction.registerBO(ApiBOBject)

Registers the object you pass as a parameter to this transaction.

Remember that all objects you want to be saved to the database must be registered and therefore, if you don’t take this step before committing the transactions, the new, unassigned object will be lost. To learn how to create business objects without assigning them to transactions, see Creating Business Objects.

  • Re-registering existing objects

To register an existing object to another transaction, call

ApiTransaction.get(ApiBOBject)

Registers the object and returns the re-registered object. Remember that now, the business object exists in both transactions – the new one and the existing one. To update the state of the business object in the initial transaction after a possible change, you should reload it from the database.

See Also

Working in Transactions

Creating Transactions

Working with Objects in Transactions

Getting Transactions

Committing Transactions

Undoing Changes and Aborting Transactions

Propagating Changes

Calling Workflows on Certain Events