Alex Rivera | Logout

Spring @Transactional - isolation, propagation

Asked 2011-12-13T14:28:47.613
564

Can someone explain the isolation & propagation parameters in the @Transactional annotation via a real-world example?

Basically when and why should I choose to change their default values?

Edit
Report

1 Answer

26

You almost never want to use Read Uncommited since it's not really ACID compliant. Read Commmited is a good default starting place. Repeatable Read is probably only needed in reporting, rollup or aggregation scenarios. Note that many DBs, postgres included don't actually support Repeatable Read, you have to use Serializable instead. Serializable is useful for things that you know have to happen completely independently of anything else; think of it like synchronized in Java. Serializable goes hand in hand with REQUIRES_NEW propagation.

I use REQUIRES for all functions that run UPDATE or DELETE queries as well as "service" level functions. For DAO level functions that only run SELECTs, I use SUPPORTS which will participate in a TX if one is already started (i.e. being called from a service function).

answered 2011-12-13T15:13:14.593

Your Answer