@Transactional(readOnly = true) 으로 얻는 이점

성능 상의 이점

Question: I think the main advantage of “transaction(readonly=True)” is not doing dirty check, not “skipping flushing” because in the read-only method which is not marked as transcation(readonly=True), it will not be actually flushed to the database.

Answer: Yes, you’re correct. The main advantage of using @Transactional(readOnly = true) is that it allows the transaction manager and the persistence provider to optimize the transaction for read operations, including skipping dirty checks. This can lead to performance improvements, especially when dealing with large amounts of data or complex data structures.

As you mentioned, if a read-only method is not marked with @Transactional(readOnly = true), it still won’t flush any changes to the database, as there are no modifications made to the entities. However, the transaction manager and the persistence provider don’t know that the method is read-only, so they still perform the usual checks and processes associated with a read-write transaction, including dirty checks. This can result in unnecessary overhead.

Using @Transactional(readOnly = true) helps the transaction manager and the persistence provider to optimize the transaction for read operations by skipping these unnecessary checks and processes, potentially improving performance.

comments powered by Disqus