public class MongoTransaction extends java.lang.Object implements Transaction
A Transaction backed by a real MongoDB multi-document transaction on a ClientSession. Unlike the legacy SessionOnlyTransaction (which only flushes the GORM session), this commits or aborts a server-side transaction so multiple writes are atomic.
The ClientSession is started with an active transaction before this object is constructed; commit() flushes the GORM session (a no-op when the DatastoreTransactionManager already flushed) and commits the server transaction, while rollback() aborts it. Both close the ClientSession and detach it from the owning session.
Commit is retried on an UnknownTransactionCommitResult error label. Whole-transaction
retry on a TransientTransactionError is intentionally not handled here: it requires
re-executing the transaction body, which the
DatastoreTransactionManager — a Spring
PlatformTransactionManager — cannot do (it only begins, commits and rolls back; the
application code between those is not re-runnable at this layer). Such retry is left to the
application (as Spring Data MongoDB's own MongoTransactionManager does), since re-running
the body would repeat its side effects.
| Constructor and description |
|---|
MongoTransaction(AbstractMongoSession session, ClientSession clientSession) |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
commit() |
|
public ClientSession |
getNativeTransaction() |
|
public boolean |
isActive() |
|
public void |
rollback() |
|
public void |
setTimeout(int timeout) |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |