I am sort of beginner in MyBatis, and I was going through below link of their documentation:
MyBatis Getting Started
What it suggest is:
Each thread should have its own instance of SqlSession. Instances of SqlSession are not to be shared and are not thread safe.
From above line what I understood is, we should use it in this way:
SqlSession session = // getting one instance of SqlSession as suggested in above link
List<Integer> result = session.selectList("getUsersId");
session.close();
So similarly where ever required, I need to create new SqlSession each time and close them. is there any better way to use it ? From better way I mean a better way to write code, pattern which should create SqlSession
for me and close it automatically.
(I am using Vaadin and MyBatis.)