What is a transaction boundary?
Asked Answered
C

3

5

I've read this article (assumes I already know what a transaction boundary is) and this SO question (can't decipher meaning of transaction boundary from that question). In other words, there are no clear definitions or attempts at definitions for transaction boundary that I have found. I understand what a transition is 100%, but what is a transaction boundary conceptually?

Calling answered 15/11, 2018 at 7:16 Comment(0)
B
5

It's where the transaction starts or is committed/rollbacked.

A method annotated with @Transactional for example defines two transaction boundaries: when the method is called, a transaction starts, and when it returns, the transaction is committed/rollbacked.

Bordelon answered 15/11, 2018 at 7:23 Comment(4)
If there is an error in my transaction between transaction boundaries, does it only rollback at the next transaction boundary as opposed to right away?Calling
By definition, it rollbacks at the next transaction boundary, since a transaction boundary defines when the transaction rollbacks. It you're asking when a transaction rollbacks when you call a transactional method, it's after the method returns or throws.Bordelon
I think I understand now, if I wanted to rollback before all the stuff in the method was done I would early-return / throw which triggers the rollback?Calling
Yes, in most cases, what causes a rollback is an exception being thrown and bubbling up until it's thrown from the method which started the transaction.Bordelon
A
1

You can read Spring Transaction boundaries reference:

For example, a gateway or service activator method could be annotated with @Transactional, or a TransactionInterceptor could be defined in an XML configuration with a pointcut expression that pointa to specific methods that should be transactional. The bottom line is that you have full control over transaction configuration and boundaries in these scenarios.

Another important factor is the boundaries of Transactions within a Message flow. When a transaction is started, the transaction context is bound to the current thread. So regardless of how many endpoints and channels you have in your Message flow your transaction context will be preserved as long as you are ensuring that the flow continues on the same thread. As soon as you break it by introducing a Pollable Channel or Executor Channel or initiate a new thread manually in some service, the Transactional boundary will be broken as well.

Arreola answered 15/11, 2018 at 7:47 Comment(0)
S
1

In simple terms, a transaction boundary marks the start and end of a transaction. Think of it as drawing a circle around a set of actions to say, "All of these actions should be treated as one big step." Within this boundary, either all of the actions happen together, or if something goes wrong, none of them happen.

Spearwort answered 14/12, 2023 at 13:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.