Is there a way to setup MyBatis with SpringMVC to have one transaction for whole http request? Generally is there something like Hibernate OpenSessionInViewFilter in MyBatis or should I write my own filter to fulfill such behavior?
Is there a way to setup MyBatis with SpringMVC to have one transaction for
Share
You are confused by notions “session” and “transaction”. OSIV opens session, in one session several transactions may coexist. Usually you should put
@Transactionalattributes to services which are used by controllers, depending on your business requirements.Moreover, one big transaction for everything is an anti-pattern. Ideally is to have a read-write transaction for a user’s actions, and then another read-only transaction is to build a response for the user. It saves resources, because database locks taken for inserts/updates are released earlier.