Spring Transactions
Transaction management with @Transactional, propagation, isolation, rollback, PlatformTransactionManager
1What is the primary role of the @Transactional annotation in Spring?
What is the primary role of the @Transactional annotation in Spring?
Odpowiedź
@Transactional indicates that a method should execute within a transactional context, ensuring atomicity of database operations. Spring automatically creates an AOP proxy around the class to handle transaction start, commit and rollback. This declarative approach greatly simplifies transaction management compared to manual programming with TransactionTemplate or PlatformTransactionManager.
2What is the default propagation type for @Transactional?
What is the default propagation type for @Transactional?
Odpowiedź
Propagation.REQUIRED is the default propagation type. With this strategy, Spring will join an existing transaction if one exists, or create a new one otherwise. This is the most common and intuitive behavior for most use cases, ensuring a transaction is always present for database operations.
3What happens if a RuntimeException is thrown in a @Transactional method?
What happens if a RuntimeException is thrown in a @Transactional method?
Odpowiedź
By default, Spring automatically rolls back the transaction when a RuntimeException (or Error) is thrown. This ensures database modifications are undone in case of unexpected errors. In contrast, checked exceptions (inheriting from Exception but not RuntimeException) do not trigger rollback by default, unless explicitly specified with rollbackFor.
Where can the @Transactional annotation be applied?
What behavior does Propagation.REQUIRES_NEW adopt?
+27 pytań z rozmów
Inne tematy rekrutacyjne Spring Boot
Spring Core - IoC & DI
Spring Boot Auto-Configuration
Spring Boot Starters
Application Properties & YAML
Logging with SLF4J & Logback
Spring Boot DevTools
Spring MVC Basics
Spring REST Controllers
Request & Response Handling
Exception Handling
Bean Validation
Spring Data JPA Basics
JPA Entities & Relationships
JPA Queries
Spring Data Repositories
Spring Security Basics
Spring Boot Actuator
Unit Testing with JUnit & Mockito
Spring Boot Testing
Profiles & Environment
RestTemplate & WebClient
Async & Scheduling
Caching with Spring
Spring WebFlux (Reactive)
Advanced Authentication & Authorization
JWT & Stateless Security
OAuth2 & Authorization Server
Spring Boot & Docker
Microservices with Spring
Spring Cloud Config
Performance Optimization
GraalVM Native Images
Opanuj Spring Boot na następną rozmowę
Uzyskaj dostęp do wszystkich pytań, flashcards, testów technicznych, ćwiczeń code review i symulatorów rozmów.
Zacznij za darmo