Spring Questions and Answers – Setting the Transaction Attribute

«
»

This set of Java Spring Multiple Choice Questions & Answers (MCQs) focuses 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
View Answer

Answer: a
Explanation: A transaction propagation behavior can be specified by the propagation transaction attribute.
advertisement

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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: c
Explanation: Otherwise, it is not necessary to run within a transaction.
advertisement

6. The current method should not run within a transaction.
a) Required
b) REQUIRES NEW
c) SUPPORTS
d) NOT SUPPORTED
View Answer

Answer: d
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: c
Explanation: 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.
advertisement

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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: b
Explanation: Later, if T1 reads the same field again, the value will be different.

12. For two transactions T1 and T2, T1 reads some rows from a table and then T2 inserts new rows into the table.
a) Dirty Read
b) Nonrepeatable read
c) Phantom read
d) Lost Updates
View Answer

Answer: c
Explanation: Later, if T1 reads the same table again, there will be additional rows.

13. For two transactions T1 and T2, they both select a row for update, and based on the state of that row, make an update to it.
a) Dirty Read
b) Nonrepeatable read
c) Phantom read
d) Lost Updates
View Answer

Answer: d
Explanation: Thus, one overwrites the other when the second transaction to commit should have waited until the first one committed before performing its selection.
advertisement

14. Isolation Levels Supported by Spring:-
a) DEFAULT
b) READ COMMITTED
c) READ UNCOMMITTED
d) All of the mentioned
View Answer

Answer: d
Explanation: Isolation Description
DEFAULT Uses the default isolation level of the underlying database. For most databases,
the default isolation level is READ COMMITTED.
READ UNCOMMITTED Allows a transaction to read uncommitted changes by other transactions. The
dirty read, nonrepeatable read, and phantom read problems may occur.
READ COMMITTED Allows a transaction to read only those changes that have been committed by
other transactions. The dirty read problem can be avoided, but the nonrepeatable
read and phantom read problems may still occur.
REPEATABLE READ Ensures that a transaction can read identical values from a field multiple times.
For the duration of this transaction, updates made by other transactions to this
field are prohibited. The dirty read and nonrepeatable read problems can be
avoided, but the phantom read problem may still occur.
SERIALIZABLE Ensures that a transaction can read identical rows from a table multiple times. For
the duration of this transaction, inserts, updates, and deletes made by other
transactions to this table are prohibited. All the concurrency problems can be
avoided, but the performance will be low.

15. The exceptions that cause a transaction to roll back or not can be specified by attribute:-
a) rollback
b) commit
c) serialize
d) none of the mentioned
View Answer

Answer: a
Explanation: Any exceptions not explicitly specified in this attribute will be handled by the default rollback rule (i.e., rolling back for unchecked exceptions and not rolling back for checked exceptions).

Sanfoundry Global Education & Learning Series – Java Spring.
To practice all areas of Java Spring, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn