Đang mở hậu trường...
4 câu hỏi kỹ thuật chủ đề Framework & Backend, song ngữ Anh-Việt, có đáp án và giải thích.
In a Spring Boot service, a fresher writes the following code: @Service public class OrderService { public void processAll(List<Order> orders) { for (Order o : orders) { saveOne(o); // direct call to method in the same class } } @Transactional public void saveOne(Order o) { orderRepository.save(o); } } When processAll() is called from a controller and saveOne() throws a RuntimeException midway, the already-saved rows are NOT rolled back. What is the main reason?
In a Spring Boot service, a junior developer writes a method `processAll()` (no annotation) that loops over a list of orders and calls `this.saveOrder(order)`, where `saveOrder` is a public method in the same class annotated with `@Transactional`. In testing, a failure inside `saveOrder` does not roll back the row that was already written. Given the app uses Spring's default proxy-based AOP, what is the most accurate explanation and fix?
You are developing a Spring Boot application. Inside a Service class, a public method `processOrder()` calls another public method `logHistory()` within the same class. Both methods are marked with @Transactional. You notice that even if `logHistory()` contains logic meant to be transactional, that configuration is ignored. Why does this happen?
A Spring Boot platform requires failed order attempts to roll back all order changes while still committing an audit record. The current service calls its own `writeAudit()` method annotated with `@Transactional(propagation = REQUIRES_NEW)`, but the audit record is rolled back with the order transaction. What should the lead establish as the preferred platform-wide design?