Spring Boot

Spring Transactions

Transaction management with @Transactional, propagation, isolation, rollback, PlatformTransactionManager

30 mülakat soruları·
Senior
1

What is the primary role of the @Transactional annotation in Spring?

Cevap

@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.

2

What is the default propagation type for @Transactional?

Cevap

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.

3

What happens if a RuntimeException is thrown in a @Transactional method?

Cevap

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.

4

Where can the @Transactional annotation be applied?

5

What behavior does Propagation.REQUIRES_NEW adopt?

+27 mülakat soruları

Bir sonraki mülakatın için Spring Boot'de uzmanlaş

Tüm sorulara, flashcards'a, teknik testlere, code review alıştırmalarına ve mülakat simülatörlerine eriş.

Ücretsiz başla