In spring, Transaction attribute defines the rules for applying policies on methods. It can have one or more parameters from the following:
1. Propagation behavior
2. Isolation level
3. Read only hints
4. Transaction timeout period
Propagation behavior is used to define the transaction boundaries.. Its very much inherited from EJBs transaction management. ADF Bounded task flow do have similar stuff. Spring has a much richer set of propagation behavior managment compare to EJBs. In brief these are:
a)PROPAGATION_MANDATORY: signifies method must be running in a transaction
b)PROPAGATION_NESTED: this is not in EJBs. It talks about creating a new child transaction if a transaction is already existing.
c)PROPAGATION_NEVER: signifies that method should not be running in a transactional context.
d)PROPAGATION_NOT_SUPPORTED: same as above but above will throw exception in case it happens. This will suspend the transaction for the duration the method runs.
e)PROPAGATION_REQUIRED: there must be a transactional context present if not there it will create a new.
f)PROPAGATION_REQUIRES_NEW: there should not be any pre-existing transactional context. it will create a new.
g)PROPAGATION_SUPPORTS: it signifies that it does not need a transactional context but if there is any it doesnt mind.
Isolation level: This has something to do with the concurrency control. When multiple transactions are running they may cause dirty reads, non repeateable reads and phantom reads. Spring provides various options depending upon the tolerance of the business use case you can use one. these are:
a)ISOLATION_DEFAULT: it uses the undelying datastore isolation policy.
b) ISOLATION_READ_UNCOMMITTED: it allows to read the data even when there are uncommited rows thus could lead dirty read or non repeateable read or phantom reads.
c) ISOLATION_READ_COMMITTED: only commited rows are read but still it may cause non-repeateable read or phantom reads.
d) ISOLATION_REPEATABLE_READ: as name suggests prevents dirty read as well as non-repeateable issues but phantom reads could be there.
e)ISOLATION_SERIALIZABLE: this brings the ACID (Atomicity, concurrancy, isolation and durability) compliance. But it is very strict and restricted so could be a performace issue.
Read only hints: Sometimes there is a requirement to just read the data from the datastore. in that case providing this attribute can make a good performance boost as datastore can apply some optimizations. But this can be done by datastore when a new transaction started. so this attribute makes sense only if propagation propety is PROPAGATION_REQUIRED, PROPAGATION_REQUIRES_NEW, or PROPAGATION_NESTED.
Transaction Timeout: This is just a way to prevent deadlocks or unresponsive threads or resource locks in the system. You can specify some timeout that will kill the transaction after the specified timeout period. again it starts when a new transaction begins so it makes sense if propagation is PROPAGATION_REQUIRED, PROPAGATION_REQUIRES_NEW, or PROPAGATION_NESTED.