ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brandon Goodin" <brandon.goo...@gmail.com>
Subject Re: Question on using Transactions with iBatis and Spring
Date Mon, 25 Jun 2007 15:29:01 GMT
There are multiple ways to handle transcations. You can handle them from the
sqlmap. This is apparently what you are referencing in the book. You can
also manage them with normal Spring mechansisms. Following is the
configuration for Spring we are using on a current project.

    <tx:annotation-driven transaction-manager="transactionManager"/>

    <!-- DAO Configuration -->

    <bean name="transactionManager" class="
        <property name="dataSource" ref="dataSource"/>

    <bean id="sqlMapClient" class="
        <property name="configLocation"
        <property name="dataSource" ref="dataSource"/>
        <property name="useTransactionAwareDataSource" value="true"/>

    <bean id="dataSource" class="some.class.here.for.a.DataSource">
        <constructor-arg index="0" value="${driverClassName}"/>
        <constructor-arg index="1" value="${databaseUrl}"/>
        <constructor-arg index="2" value="${userName}"/>
        <constructor-arg index="3" value="${password}"/>

We do not start transactions on the SqlMap rather we use the Spring
transaction callback or annotations. It would also be possible to configure
the transactions in the context xml.

Callback example:
TransactionTemplate tt = new TransactionTemplate(transactionManager);

tt.execute(new TransactionCallbackWithoutResult() {
  public void doInTransactionWithoutResult(TransactionStatus
transactionStatus) {

Annotation Example:
public void insertMethodOnServiceClass(MyObject myObject) {

Hope that helps,
Brandon Goodin

On 6/25/07, Robert Glover <robertgloverjr@yahoo.com> 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