You are not logged in.
Pages: 1
As part of a 3-tier architecture (SOA), I need to implement a business function that operates on three different ORM classes, each corresponding to a different table in the database.
My goal is to ensure data consistency by using a transaction: if an error occurs while saving any of the entities, I want all changes to be rolled back.
However, in mORMot 2, the TransactionBegin(Table, SessionID) method appears to support only one class at a time.
Therefore, I am wondering:
How can I manage a transaction that spans multiple ORM classes (tables) in mORMot?
Does using transactions in mORMot block other users from accessing or modifying the database during the transaction?
Offline
Multiple ORM classes transaction is indeed not supported.
What you should do instead of ORM-level transaction is to use a TRestBatch, which will write everything at once, could involve several ORM classes, and will create the SQL transactions for you.
And it will also be much faster, without any client-server round trip, or blocking other readers/writers.
Online
Is it possible to give me an example that explains how to use TRestBatch to insert 3 objects, where I need to get the ID of the first object and use it in the second object?
Offline
An alternative of TSynUniqueIdentifierGenerator.ComputeNew is using of sequences to compute the ID's before building the Batch.
Offline
TSynUniqueIdentifierGenerator — in which unit is it located?
Offline
@fatimaEzz, unit is "mormot.crypt.secure".
protip: consider using a specialized tool to perform recursive content searches within a specified folder (/mormot/src), eg. Agent Ransack (free).
Last edited by flydev (2025-06-20 13:39:59)
Offline
Pages: 1