Search code examples
javaspring-bootspring-transactions

@Transactional applicability for read methods


I want to add Transactional support for my service class. If I add javax.transaction.Transactional annotation to Class which contains both read write methods how it behave?

By doing that for read methods in that class, does is make execution slow. Or does spring-boot ignore it for read methods?


Solution

  • For read operations, we use org.springframework.transaction.annotation.Transactional with parameter @Transactional(readOnly=true)

    This just serves as a hint for the actual transaction subsystem; * it will not necessarily cause failure of write access attempts. and It will not slow execution.