Spring Transactions Flashcards

1
Q

What is a transaction?

A

A transaction is an indivisible unit of work

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the 4 characteristics of a transaction?

A
  1. Atomic
  2. Consistent
  3. Isolated
  4. Durable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the 3 things you must do to enable Spring Transactions?

A
  1. @EnableTransactionManagement on configuration class (optional for Spring Boot)
  2. Create a PlatformTransactionManager bean
  3. @Transactional on bean class or its methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Name some of the readily available implementations of PlatformTransactionManager

A
  • MongoTransactionManager
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

By default, what exception type rolls back a transaction?

A

RuntimeException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Do checked exceptions roll back transactions?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can you customize the exception type that should cause a transaction rollback?

A

@Transactional(rollbackFor=…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the 7 transaction propagation levels?

A
  1. Mandatory
  2. Never
  3. Not_Supported
  4. Supports
  5. Required (default)
  6. Requires_New
  7. Nested
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Define “transaction propagation”

A

Transaction propagation relates to how a transaction behaves when calling another transaction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why should you consider using @Transactional(readOnly=true) when making multiple queries to a database?

A

Faster performance by using a single connection instead of 1 connection per query

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

True or False

The higher the transaction isolation level the slower the performance

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Define “transaction isolation”

A

Transaction isolation relates to how isolated a transaction is from other transactions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the 5 levels of transaction isolation?

A
  1. DEFAULT
  2. READ_COMMITTED
  3. READ_UNCOMMITED
  4. REPEATABLE_READ
  5. SERIALIZABLE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

From what package should you import @Transactional?

A

From springframework not javax

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What behavior does @Transactional have on @Test methods?

A

Rolls back database operations after execution. This means you don’t have to worry about cleaning up your database after testing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does @Commit do?

A

Forces @Test methods annotated with @Transactional to commit database operations

17
Q

How is transaction demarcation implemented behind the scenes?

A

@Around advice method