I am really confused about distributing transactions in Spring with Hibernate. I use Spring annotations @Transactionalfor my service level methods. Some are marked as "read-only = true". If one of my read-only methods calls a method that is not read-only, how can I handle this?
I think I can tag all my read and write methods to support distribution REQUIRES_NEW, but this will lead to behavior that I cannot want - i.e. I want only a new transaction in the case where the read-only method is called the read-write method. If the read-write method calls another read-write method, I don't need a new transaction.
Given all this, I don’t understand how Open Session In View (OSIV) works! Of course, using OSIV in Spring, you OpenSessionInViewFiltermust start the transaction before calling the service methods. In this case, you must determine if the transaction is read-only or read-write. BUT, how can he know this? He does not know what will happen under the covers of the service level.
I am completely in the dark on all this and would like someone to explain it to me!
source
share