Java Spring Multiple Choice Questions & Answers (MCQs) on “Setting the Transaction Attribute”.
1. A transaction propagation behavior can be specified by the:-
a) propagation
b) consistency
c) isolation
d) All of the mentioned
Answer: a
Clarification: A transaction propagation behavior can be specified by the propagation transaction attribute.
2. Transaction propagation behavior are defined in the:-
a) org.springframework.transaction.Transaction
b) org.springframework.transaction.TransactionDefinition
c) all of the mentioned
d) none of the mentioned
Answer: b
Clarification: These behaviors are defined in the org.springframework.transaction.TransactionDefinition interface.
3. If there’s an existing transaction in progress, the current method should run within this transaction.
a) Required
b) REQUIRES NEW
c) SUPPORTS
d) NOT SUPPORTED
Answer: a
Clarification: If there’s an existing transaction in progress, the current method should run within this transaction. Otherwise, it should start a new transaction and run within its own transaction.
4. The current method must start a new transaction and run within its own transaction.
a) Required
b) REQUIRES NEW
c) SUPPORTS
d) NOT SUPPORTED
Answer: b
Clarification: The current method must start a new transaction and run within its own transaction. If there’s an existing transaction in progress, it should be suspended.
5. If there’s an existing transaction in progress, the current method can run within this transaction.
a) Required
b) REQUIRES NEW
c) SUPPORTS
d) NOT SUPPORTED
Answer: c
Clarification: Otherwise, it is not necessary to run within a transaction.
6. The current method should not run within a transaction.
a) Required
b) REQUIRES NEW
c) SUPPORTS
d) NOT SUPPORTED
Answer: d
Clarification: The current method should not run within a transaction. If there’s an existing transaction in progress, it should be suspended.
7. The current method must run within a transaction.
a) Required
b) MANDATORY
c) SUPPORTS
d) NOT SUPPORTED
Answer: b
Clarification: The current method must run within a transaction. If there’s no existing transaction in progress, an exception will be thrown.
8. The current method should not run within a transaction. If there’s an existing transaction in progress, an exception will be thrown.
a) Required
b) MANDATORY
c) SUPPORTS
d) NEVER
Answer: d
Clarification: The current method should not run within a transaction. If there’s an existing transaction in progress, an exception will be thrown.
9. If there’s an existing transaction in progress, the current method should run within the nested transaction.
a) Required
b) MANDATORY
c) NESTED
d) NEVER
Answer: c
Clarification: If there’s an existing transaction in progress, the current method should run within the nested transaction (supported by the JDBC 3.0 save point feature) of this transaction. Otherwise, it should start a new transaction and run within its own transaction.
10. For two transactions T1 and T2, T1 reads a field that has been updated by T2 but not yet committed.
a) Dirty Read
b) Nonrepeatable read
c) Phantom read
d) Lost Updates
Answer: a
Clarification: Later, if T2 rolls back, the field read by T1 will be temporary and invalid.
11. For two transactions T1 and T2, T1 reads a field and then T2 updates the field.
a) Dirty Read
b) Nonrepeatable read
c) Phantom read
d) Lost Updates
