Received: by 10.66.88.42 with SMTP id bd10mr3351116pab.18.1349597483149; Sun, 07 Oct 2012 01:11:23 -0700 (PDT) X-BeenThere: mybatis-user@googlegroups.com Received: by 10.68.226.100 with SMTP id rr4ls19503982pbc.2.gmail; Sun, 07 Oct 2012 01:11:21 -0700 (PDT) Received: by 10.68.197.70 with SMTP id is6mr4064476pbc.14.1349597480909; Sun, 07 Oct 2012 01:11:20 -0700 (PDT) Date: Sun, 7 Oct 2012 01:11:20 -0700 (PDT) From: Prabu Uthirapathi To: mybatis-user@googlegroups.com Message-Id: In-Reply-To: References: <22d2a373-b025-4844-a6c4-b56193a5cb2c@googlegroups.com> <7ff0af3f-37cc-4a9e-86cf-93e020299112@googlegroups.com> Subject: Re: Is MyBatis(3.0) mapper thread safe MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_76_2844382.1349597480042" ------=_Part_76_2844382.1349597480042 Content-Type: multipart/alternative; boundary="----=_Part_77_24022380.1349597480042" ------=_Part_77_24022380.1349597480042 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit currently all the mapped statements are loaded via the following config Is that OK? On Saturday, October 6, 2012 10:33:14 AM UTC+5:30, Eduardo wrote: > > BTW the spring application context will not be started until all mapped > statements are loaded. That loading process is not thread safe and it is > expected to be done by the startup thread. > > If you are loading mappers lazily, thread safety problems may arise. Not > sure about that. > > 2012/10/6 Eduardo Macarron > > >> Configuration is a singleton both when using MyBatis alone and also when >> using it with Spring. >> >> Please first check your config againts the mybatis-spring manual. >> >> >> 2012/10/6 Duc Trung TRAN > >> >>> Eduardo, >>> >>> Yes, I've been using SqlSessionTemplate And it does not work. The >>> thread safety problem is from within Configuration class of Ibatis which is >>> used by SqlSession. >>> >>> It's possible that i did not use spring mybatis api correctly. But can >>> you first try to do some tests as I suggest? >>> >>> >>> >>> 2012/10/5 Eduardo Macarron > >>> >>>> A SqlSession got from SqlSessionFactory is not thread safe as the >>>> manual says >>>> >>>> See Scope & Livecycle at >>>> http://www.mybatis.org/core/getting-started.html >>>> >>>> But when using Spring, mappers use a different SqlSession that is both >>>> transactional and thread safe. >>>> >>>> http://www.mybatis.org/spring/sqlsession.html >>>> >>>> >>>> 2012/10/5 Duc Trung TRAN > >>>> >>>>> I don't know how UserMapper is implemented but i suppose it use >>>>> sqlSession internally. In this case it is not thread safe when mapped >>>>> statements are not loaded. You can test by creating some threads which >>>>> concurrently execute the same method in UserMapper. There will be >>>>> exceptions raised. >>>>> >>>>> But once the mapped statement is loaded, it's thread safe. >>>>> >>>>> >>>>> >>>>> 2012/10/5 Eduardo Macarron > >>>>> >>>>>> yes, it is. >>>>>> >>>>>> >>>>>> Is userMapper thread safe (I am using spring-mybatis)? >>>>>>> >>>>>>> >>>>> >>>> >>> >> > ------=_Part_77_24022380.1349597480042 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit currently all the mapped statements are loaded via the following config 

          <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.xyz.persistence" />
    </bean>


Is that OK? 



On Saturday, October 6, 2012 10:33:14 AM UTC+5:30, Eduardo wrote:
BTW the spring application context will not be started until all mapped statements are loaded. That loading process is not thread safe and it is expected to be done by the startup thread.

If you are loading mappers lazily, thread safety problems may arise. Not sure about that.

2012/10/6 Eduardo Macarron <eduardo....@gmail.com>
Configuration is a singleton both when using MyBatis alone and also when using it with Spring. 

Please first check your config againts the mybatis-spring manual.


2012/10/6 Duc Trung TRAN <ductru...@gmail.com>
Eduardo,

Yes, I've been using SqlSessionTemplate And it does not work.  The thread safety problem is from within Configuration class of Ibatis which is used by SqlSession. 

It's possible that i did not use spring mybatis api correctly. But can you first try to do some tests as I suggest?

 

2012/10/5 Eduardo Macarron <eduardo....@gmail.com>
A SqlSession got from SqlSessionFactory is not thread safe as the manual says


But when using Spring, mappers use a different SqlSession that is both transactional and thread safe.



2012/10/5 Duc Trung TRAN <ductru...@gmail.com>
I don't know how UserMapper is implemented but i suppose it use sqlSession internally. In this case it is not thread safe when mapped statements are not loaded. You can test by creating some threads which concurrently execute the same method in UserMapper. There will be exceptions raised.

But once the mapped statement is loaded, it's thread safe.



2012/10/5 Eduardo Macarron <eduardo....@gmail.com>
yes, it is.


Is userMapper thread safe (I am using spring-mybatis)? 






------=_Part_77_24022380.1349597480042-- ------=_Part_76_2844382.1349597480042--