Should we use transaction in spring select queries?
I saw that Spring adds Transaction(readOnly=true)
to all default select queries but I couldn’t understand it, if we don’t use custom isolation levels.
Actually, my question is so clear:
First Case:
@Service
public class OrderService {
@Autowired
private OrderRepository orderRepository;
@Transactional(readOnly = true)
public List<Order> getAllOrders() {
return orderRepository.findAll();
}
}
Second Case:
@Service
public class ProductService {
@Autowired
private ProductRepository productRepository;
public List<Product> getAllProducts() {
return productRepository.findAll();
}
}
Both of them use same isolation level (default mysql repeatable-read
) so is there a case to get different result from these two queries?
Note: I believe that Case2 will have higher performance than Case2 because there isn’t extra transaction-manager-wrapper.