Java Spring Multiple Choice Questions & Answers (MCQs) on “Transaction Management”.
1. Transactions can be described with key properties:-
a) Atomicity
b) Consistency
c) Isolation
d) All of the mentioned
Answer: d
Clarification: The concept of transactions can be described with four key properties: atomicity, consistency, isolation, and durability (ACID).
• Atomicity: A transaction is an atomic operation that consists of a series of actions.
The atomicity of a transaction ensures that the actions either complete entirely or
take no effect at all.
• Consistency: Once all actions of a transaction have completed, the transaction is
committed. Then your data and resources will be in a consistent state that
conforms to business rules.
• Isolation: Because there may be many transactions processing with the same data
set at the same time, each transaction should be isolated from others to prevent
data corruption.
• Durability: Once a transaction has completed, its result should be durable to
survive any system failure (imagine if the power to your machine was cut right in
the middle of a transaction commit). Usually, the result of a transaction is
written to persistent storage.
2. To access a database running on the Derby server, you have to add:-
a) Derby client library
b) Tomcat client library
c) All of the mentioned
d) None of the mentioned
Answer: a
Clarification: To access a database running on the Derby server, you have to the Derby client library to your CLASSPATH.
3. Spring’s transaction support offers a set of technology-independent facilities, including transaction managers.
a) org.springframework.transaction.PlatformTransactionManager
b) org.springframework.transaction.support.TransactionTemplate
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: Spring’s transaction support offers a set of technology-independent facilities, a transaction template (e.g., org.springframework.transaction.support.TransactionTemplate), and transaction declaration support to simplify your transaction management tasks.
4. Spring’s core transaction management abstraction is based on the interface:-
a) PlatformTransaction
b) PlatformTransactionManager
c) TransactionManager
d) PlatformManager
Answer: b
Clarification: It encapsulates a set of technology-independent methods for transaction management.
5. The PlatformTransactionManager interface provides methods for working with transactions:
a) getTransaction(TransactionDefinition definition)
b) commit(TransactionStatus status)
c) rollback(TransactionStatus status)
d) all of the mentioned
Answer: d
Clarification:
• TransactionStatus getTransaction(TransactionDefinition definition) throws
TransactionException
• void commit(TransactionStatus status) throws TransactionException;
• void rollback(TransactionStatus status) throws TransactionException;
6. Spring has several built-in implementations of PlatformTransactionManager interface for use with different transaction management APIs.
a) True
b) False
Answer: a
Clarification:
• If you have to deal with only a single data source in your application and access it
with JDBC, DataSourceTransactionManager should meet your needs.
• If you are using JTA for transaction management on a Java EE application server,
you should use JtaTransactionManager to look up a transaction from the
application server. Additionally, JtaTransactionManager is appropriate for
distributed transactions (transactions that span multiple resources). Note that
while it’s common to use a JTA transaction manager to integrate the application
servers’ transaction manager, there’s nothing stopping you from using a stand-
alone JTA transaction manager such as Atomikos.
• If you are using an object/relational mapping framework to access a database, you
should choose a corresponding transaction manager for this framework, such as
HibernateTransactionManager and JpaTransactionManager.
7. A transaction manager is declared in the Spring IoC container as a normal bean.
a) True
b) False
