Spring Transactions Flashcards
What is a transaction?
A transaction is an indivisible unit of work
What are the 4 characteristics of a transaction?
- Atomic
- Consistent
- Isolated
- Durable
What are the 3 things you must do to enable Spring Transactions?
- @EnableTransactionManagement on configuration class (optional for Spring Boot)
- Create a PlatformTransactionManager bean
- @Transactional on bean class or its methods
Name some of the readily available implementations of PlatformTransactionManager
- MongoTransactionManager
By default, what exception type rolls back a transaction?
RuntimeException
Do checked exceptions roll back transactions?
No
How can you customize the exception type that should cause a transaction rollback?
@Transactional(rollbackFor=…)
What are the 7 transaction propagation levels?
- Mandatory
- Never
- Not_Supported
- Supports
- Required (default)
- Requires_New
- Nested
Define “transaction propagation”
Transaction propagation relates to how a transaction behaves when calling another transaction
Why should you consider using @Transactional(readOnly=true)
when making multiple queries to a database?
Faster performance by using a single connection instead of 1 connection per query
True or False
The higher the transaction isolation level the slower the performance
True
Define “transaction isolation”
Transaction isolation relates to how isolated a transaction is from other transactions
What are the 5 levels of transaction isolation?
- DEFAULT
- READ_COMMITTED
- READ_UNCOMMITED
- REPEATABLE_READ
- SERIALIZABLE
From what package should you import @Transactional?
From springframework not javax
What behavior does @Transactional have on @Test methods?
Rolls back database operations after execution. This means you don’t have to worry about cleaning up your database after testing