ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Lamey <cla...@localmatters.com>
Subject Re: Question on using Transactions with iBatis and Spring
Date Mon, 25 Jun 2007 15:51:12 GMT

I think it depends on how you are setting your data source.  If you are
setting the iBATIS DataSource via the Spring SqlMapClientFactoryBean in
a Spring context, you are using an EXTERNAL DataSource as far as iBATIS
is concerned.  iBATIS at that point wouldn't have anything to do with
the creation of configuration of the DataSource or any transaction
management.  Note that means any explicit transaction Java code
(startTransaction()/endTransaction()/etc) you might have will also be

If you don't set a DataSource on the Spring SqlMapClientFactoryBean in
your context, then you need to handle the DataSource and transaction
handling in the sqlmap config file.

IMHO, using the Spring declarative transaction handling is the way to
go.  It's completely transparent, you don't need to write any code for
it, and it keeps your application loosely coupled.


On Mon, 2007-06-25 at 08:08 -0700, Robert Glover wrote:
> I am confused over how to use transactions with iBatis and Spring. (I'm
> actually using iBatis and Abator and Spring).
>    The Spring 2.0.6 manual (section 12.5) says,
>     "...Transaction management can be handled through Spring's standard
> facilities.  There are no special transaction strategies for iBATIS, as there
> is no special transactional resource involved other than a JDBC Connection.
> Hence, Spring's standard JDBC DataSourceTransactionManager or
> JtaTransactionManager are perfectly sufficient. ..."
>     On the other hand, page 152 of the book "iBatis in Action" by
> Begin/Goddin/Meadors says:  "...Local transaction are configured in the iBatis
> SQL Map configuration XML file as a JDBC transaction manager."  The iBatis book
> then shows an example of using "sqlMapClient.startTractsion()",
> "sqlMapClient.commitTransaction", and "sqlMapClient.endTransaction()".
>     In my sql-map-config.xml I don't have any transaction related statements at
> all.  In my Spring application context file I have: 
> <!-- SqlMap setup for iBATIS Database Layer -->
> <bean id="sqlMapClient"    
> class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
>     <property name="configLocation" value="WEB-INF/sql-map-config.xml"/>
>     <property name="dataSource" ref="dataSource"/>
> </bean>
>      Can anybody add any light on using iBatis with Spring and transactions?
> Note that because I use Abator (a wonderful facility) I don't write an iBatis
> code at all, I just invoke the methods on the DAOs that Abator creates.
> Robert

View raw message