Loading

Quipoin Menu

Learn • Practice • Grow

spring / Transaction Management
interview

Q1. What is transaction management in Spring?
Spring provides a consistent abstraction for transaction management, supporting both programmatic and declarative transactions. It allows you to manage transactions across different APIs (JPA, JDBC, etc.) using a unified model. Declarative transactions use @Transactional annotation.

Q2. What is @Transactional?
@Transactional is an annotation used to declare that a method or class should be executed within a transactional context. It can be applied to interfaces, classes, or methods. Attributes define propagation, isolation, timeout, readOnly, and rollback rules.

Q3. What are the propagation levels in Spring transactions?
Propagation defines how transactions relate to each other. Common levels: REQUIRED (join existing or create new), REQUIRES_NEW (suspend existing, create new), NESTED (savepoint within existing), MANDATORY (must exist), NEVER (must not exist), SUPPORTS (optional), NOT_SUPPORTED (run non-transactionally).

Q4. What is isolation level?
Isolation level defines how transaction changes are visible to others. Levels: DEFAULT (use DB default), READ_UNCOMMITTED (dirty reads allowed), READ_COMMITTED (prevents dirty reads), REPEATABLE_READ (prevents non-repeatable reads), SERIALIZABLE (highest isolation).

Q5. How do you configure transaction management in Spring?
Use @EnableTransactionManagement in configuration, and define a PlatformTransactionManager bean (e.g., DataSourceTransactionManager for JDBC, JpaTransactionManager for JPA). Spring Boot auto-configures this if you have Spring Data JPA or JDBC starters.