Closed GoogleCodeExporter closed 9 years ago
If you are using CMT you should use the ManagedTransactionFactory instead of
JdbcTransactionFactory.
Give it a try.
Original comment by eduardo.macarron
on 12 Feb 2011 at 11:04
i have use the ManagedTransactionFactory
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="mybatis-config.xml" />
<property name="dataSource" ref="dataSource" />
<property name="transactionFactory">
<bean class="org.apache.ibatis.transaction.managed.ManagedTransactionFactory" />
</property>
</bean>
but in org.apache.ibatis.executor.loader.ResultLoader.selectList()
mybatis use the JdbcTransaction eg. Transaction tx = new JdbcTransaction(conn,
false);
Original comment by garth...@gmail.com
on 12 Feb 2011 at 2:26
You are right, the TransactionFactory should be read from Environment.
Original comment by eduardo.macarron
on 12 Feb 2011 at 4:16
Sorry I just read the stacktrace :) Thanks a lot for your detailed report.
Hope it is fixed in r3622. This is difficult to test so I just checked nothing
gets broken. I have refreshed the 3.0.5-SNAPSHOT at download page (not in
sonatype repo). Could you give it a try?
Original comment by eduardo.macarron
on 12 Feb 2011 at 4:56
i have try it in jboss
it works well
thanks!
Original comment by garth...@gmail.com
on 14 Feb 2011 at 7:10
This fix is not sufficient for Spring-managed transactions when using
mybatis-spring because the Executor's queries will only participate in the
current transaction if the Connection is retrieved by calling
org.springframework.jdbc.datasource.DataSourceUtils.getConnection(ds) instead
of ds.getConnection(). Presumably mybatis-guice has the same problem. So one
way this could be fixed is to define a ConnectionFactory interface (similar to
the TransactionFactory that is in org.apache.ibatis.mapping.Environment) that
would be implemented by mybatis-spring, mybatis-guice, and mybatis.
Here is a scenario that can reproduce this problem:
1. Delete row from table A.
2. Within the same transaction boundary, lazy load a collection from table A.
Lazy loaded result will contain the deleted row but it should not.
Original comment by patrick....@3pillarglobal.com
on 17 Mar 2011 at 7:58
You are right Patrick. We already discussed that limitation in the dev list.
MyBatis transaction interface should also include the connection retrieval. So
the full connection livecycle can be managed by a plugin.
I don think this will be addressed in a short time.
Anyway this should not be a common problem.
Original comment by eduardo.macarron
on 17 Mar 2011 at 9:37
I created Issue 279 for the Spring transaction bug.
Original comment by patrick....@3pillarglobal.com
on 25 Mar 2011 at 4:19
Original comment by eduardo.macarron
on 3 Mar 2012 at 9:11
Original issue reported on code.google.com by
garth...@gmail.com
on 12 Feb 2011 at 9:49