You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by bala r <ba...@gmail.com> on 2008/08/21 22:10:15 UTC

Spring with IBatis and Transaction Manager Helps.

Hi,

I have to implement TransacationManager in my module using Spring with
Ibatis.

Here is my requirments.

TransacationProcessor  -
  --Open Transacation
  --Call LoopProcessor(process multiple files )
           --- Call DatabaseProcessor
                      -- Call SQLMqpClient Insert/update/delete.
           -- Call OtherProcessor do Work.
  --All Success then Committransaction.
  -- If fails rollbackTransacation.
  --End Transaction.

Any documents for handling Spring and Ibaris or any examples i can get from
any source?
I tried google Spring with Ibatis transaction but couldnt find any much
information.

Thanks
bala.

Re: Spring with IBatis and Transaction Manager Helps.

Posted by bala r <ba...@gmail.com>.
Hi,

I am looking some good reference for Spring Declarative transacation with
Ibatis.

Thanks
Bala.
On Thu, Aug 21, 2008 at 4:31 PM, Sundar Sankar <fa...@gmail.com> wrote:

> Did you go through the Spring reference pdf. They have these explained.
> Even google would direct you the HTML chapter of the PDF.
>
>
> On Thu, Aug 21, 2008 at 1:10 PM, bala r <ba...@gmail.com> wrote:
>
>> Hi,
>>
>> I have to implement TransacationManager in my module using Spring with
>> Ibatis.
>>
>> Here is my requirments.
>>
>> TransacationProcessor  -
>>   --Open Transacation
>>   --Call LoopProcessor(process multiple files )
>>            --- Call DatabaseProcessor
>>                       -- Call SQLMqpClient Insert/update/delete.
>>            -- Call OtherProcessor do Work.
>>   --All Success then Committransaction.
>>   -- If fails rollbackTransacation.
>>   --End Transaction.
>>
>> Any documents for handling Spring and Ibaris or any examples i can get
>> from any source?
>> I tried google Spring with Ibatis transaction but couldnt find any much
>> information.
>>
>> Thanks
>> bala.
>>
>
>

Re: Spring with IBatis and Transaction Manager Helps.

Posted by Sundar Sankar <fa...@gmail.com>.
Did you go through the Spring reference pdf. They have these explained. Even
google would direct you the HTML chapter of the PDF.

On Thu, Aug 21, 2008 at 1:10 PM, bala r <ba...@gmail.com> wrote:

> Hi,
>
> I have to implement TransacationManager in my module using Spring with
> Ibatis.
>
> Here is my requirments.
>
> TransacationProcessor  -
>   --Open Transacation
>   --Call LoopProcessor(process multiple files )
>            --- Call DatabaseProcessor
>                       -- Call SQLMqpClient Insert/update/delete.
>            -- Call OtherProcessor do Work.
>   --All Success then Committransaction.
>   -- If fails rollbackTransacation.
>   --End Transaction.
>
> Any documents for handling Spring and Ibaris or any examples i can get from
> any source?
> I tried google Spring with Ibatis transaction but couldnt find any much
> information.
>
> Thanks
> bala.
>

Re: Spring with IBatis and Transaction Manager Helps.

Posted by gip_ <gi...@accenture.com>.
However the post is old, I post how I solved your same problem.

Try to add this property to the datasource to disable autocommit:
<property name="defaultAutoCommit">
	<value>false</value> 
</property>

Regards,
Gip



bala r wrote:
> 
> Hi Brian,
> 
> I added the rollback-for atrribute to handle rollback if there are any
> errors .
> <tx:method name="doProcess*" read-only="true"
> rollback-for="com.workflow.exceptions.MultipleErrorsException"/>
> 
> Here is the AOPconfig. The transactionProcessors is the service layer
> which
> calls DAO to insert/Update..
> <aop:config>
>           <aop:pointcut id="daoServiceOperation" expression="execution(*
> com.processors.TransactionProcessor.*.*(..))" />
>           <aop:advisor advice-ref="txAdvice"
> pointcut-ref="daoServiceOperation" />
>      </aop:config>
> 
> For testing right after Insert/Update i throw MultipleErrorsException to
> verify the rollback. But rollback is not happening and the transacation is
> being commited.
> 
> I need to handle Rollback After DAO call my transaction processor also
> calls
> someother workflow processor. If there are any errors in teh other
> workflows
> then i need to rollback the transaction..
> 
> Any ideas how to handle transaction here?
> 
> Thanks
> Bala
> 
> 
> 
> On Fri, Aug 22, 2008 at 11:04 AM, bala r <ba...@gmail.com> wrote:
> 
>> Hi Brian,
>>
>> Thank you so much.. I will try your config.. I want to handle the
>> transaction in the Service layer not in DAO.
>> I will implement the same config and call the AOP in the service layer.
>>
>> Thanks
>> Bala.
>>
>>
>> On Fri, Aug 22, 2008 at 7:36 AM, Brian Parkinson
>> <pa...@avaning.com>wrote:
>>
>>>  Hi Bala:
>>>
>>> I am using Spring with iBatis with transations. Below is the config that
>>> I
>>> am using - note the use of the spring tx:* AOP transaction injection.
>>> There
>>> are docs in the spring project related to how to set this up (mine below
>>> is
>>> pretty much a copy of that example).
>>>
>>> Hope it helps.
>>>
>>> Brian Parkinson.
>>>
>>> --- x8 snip
>>>
>>>  SqlMapConfig contains:
>>>
>>>  <transactionManager type="EXTERNAL">
>>>   <dataSource type="DBCP">
>>>   </dataSource>
>>>  </transactionManager>
>>>
>>>  Spring transactions:
>>>
>>>  <bean id="txManager"
>>> class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
>>>   <property name="dataSource" ref="dataSource"/>
>>>  </bean>
>>>
>>>  <tx:advice id="txAdvice" transaction-manager="txManager">
>>>   <tx:attributes>
>>>    <tx:method name="get*" read-only="true" />
>>>    <tx:method name="*" />
>>>   </tx:attributes>
>>>  </tx:advice>
>>>
>>>  <aop:config>
>>>   <aop:pointcut id="daoServiceOperation" expression="execution(*
>>> com.ecobee.foundation.dao.ibatis.*.*(..))" />
>>>   <aop:advisor advice-ref="txAdvice" pointcut-ref="daoServiceOperation"
>>> />
>>>  </aop:config>
>>>
>>> Spring datasource:
>>>
>>>  <bean id="mapConfig"
>>> class="org.springframework.core.io.ClassPathResource">
>>>   <constructor-arg>
>>>    <value>com/ecobee/foundation/dao/ibatis/SqlMapConfig.xml</value>
>>>   </constructor-arg>
>>>  </bean>
>>>
>>>  <bean id="dataSource"
>>> class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
>>>   <property name="targetDataSource">
>>>    <ref local="dataSourceImpl"/>
>>>   </property>
>>>  </bean>
>>>
>>>  <bean id="dataSourceImpl"
>>> class="org.apache.commons.dbcp.BasicDataSource"
>>> destroy-method="close">
>>>   <property name="driverClassName" value="com.mysql.jdbc.Driver" />
>>>   <property name="url" value="jdbc:mysql:///ecobee" />
>>>   <property name="username" value="XXX" />
>>>   <property name="password" value="YYY" />
>>>   <property name="initialSize" value="10" />
>>>   <property name="maxActive" value="100" />
>>>   <property name="maxIdle" value="16" />
>>>   <property name="maxWait" value="2000" />
>>>  </bean>
>>>
>>>  <bean id="sqlMapClient"
>>> class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
>>>   <property name="dataSource" ref="dataSource" />
>>>   <property name="configLocation" ref="mapConfig" />
>>>  </bean>
>>>
>>>
>>>
>>>
>>>  ------------------------------
>>> *From:* bala r [mailto:balar4u@gmail.com]
>>> *Sent:* Thursday, August 21, 2008 4:10 PM
>>> *To:* user-java@ibatis.apache.org
>>> *Subject:* Spring with IBatis and Transaction Manager Helps.
>>>
>>>  Hi,
>>>
>>> I have to implement TransacationManager in my module using Spring with
>>> Ibatis.
>>>
>>> Here is my requirments.
>>>
>>> TransacationProcessor  -
>>>   --Open Transacation
>>>   --Call LoopProcessor(process multiple files )
>>>            --- Call DatabaseProcessor
>>>                       -- Call SQLMqpClient Insert/update/delete.
>>>            -- Call OtherProcessor do Work.
>>>   --All Success then Committransaction.
>>>   -- If fails rollbackTransacation.
>>>   --End Transaction.
>>>
>>> Any documents for handling Spring and Ibaris or any examples i can get
>>> from any source?
>>> I tried google Spring with Ibatis transaction but couldnt find any much
>>> information.
>>>
>>> Thanks
>>> bala.
>>>
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Spring-with-IBatis-and-Transaction-Manager-Helps.-tp19095933p21131106.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: Spring with IBatis and Transaction Manager Helps.

Posted by bala r <ba...@gmail.com>.
Hi Brian,

I added the rollback-for atrribute to handle rollback if there are any
errors .
<tx:method name="doProcess*" read-only="true"
rollback-for="com.workflow.exceptions.MultipleErrorsException"/>

Here is the AOPconfig. The transactionProcessors is the service layer which
calls DAO to insert/Update..
<aop:config>
          <aop:pointcut id="daoServiceOperation" expression="execution(*
com.processors.TransactionProcessor.*.*(..))" />
          <aop:advisor advice-ref="txAdvice"
pointcut-ref="daoServiceOperation" />
     </aop:config>

For testing right after Insert/Update i throw MultipleErrorsException to
verify the rollback. But rollback is not happening and the transacation is
being commited.

I need to handle Rollback After DAO call my transaction processor also calls
someother workflow processor. If there are any errors in teh other workflows
then i need to rollback the transaction..

Any ideas how to handle transaction here?

Thanks
Bala



On Fri, Aug 22, 2008 at 11:04 AM, bala r <ba...@gmail.com> wrote:

> Hi Brian,
>
> Thank you so much.. I will try your config.. I want to handle the
> transaction in the Service layer not in DAO.
> I will implement the same config and call the AOP in the service layer.
>
> Thanks
> Bala.
>
>
> On Fri, Aug 22, 2008 at 7:36 AM, Brian Parkinson <pa...@avaning.com>wrote:
>
>>  Hi Bala:
>>
>> I am using Spring with iBatis with transations. Below is the config that I
>> am using - note the use of the spring tx:* AOP transaction injection. There
>> are docs in the spring project related to how to set this up (mine below is
>> pretty much a copy of that example).
>>
>> Hope it helps.
>>
>> Brian Parkinson.
>>
>> --- x8 snip
>>
>>  SqlMapConfig contains:
>>
>>  <transactionManager type="EXTERNAL">
>>   <dataSource type="DBCP">
>>   </dataSource>
>>  </transactionManager>
>>
>>  Spring transactions:
>>
>>  <bean id="txManager"
>> class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
>>   <property name="dataSource" ref="dataSource"/>
>>  </bean>
>>
>>  <tx:advice id="txAdvice" transaction-manager="txManager">
>>   <tx:attributes>
>>    <tx:method name="get*" read-only="true" />
>>    <tx:method name="*" />
>>   </tx:attributes>
>>  </tx:advice>
>>
>>  <aop:config>
>>   <aop:pointcut id="daoServiceOperation" expression="execution(*
>> com.ecobee.foundation.dao.ibatis.*.*(..))" />
>>   <aop:advisor advice-ref="txAdvice" pointcut-ref="daoServiceOperation" />
>>  </aop:config>
>>
>> Spring datasource:
>>
>>  <bean id="mapConfig"
>> class="org.springframework.core.io.ClassPathResource">
>>   <constructor-arg>
>>    <value>com/ecobee/foundation/dao/ibatis/SqlMapConfig.xml</value>
>>   </constructor-arg>
>>  </bean>
>>
>>  <bean id="dataSource"
>> class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
>>   <property name="targetDataSource">
>>    <ref local="dataSourceImpl"/>
>>   </property>
>>  </bean>
>>
>>  <bean id="dataSourceImpl" class="org.apache.commons.dbcp.BasicDataSource"
>> destroy-method="close">
>>   <property name="driverClassName" value="com.mysql.jdbc.Driver" />
>>   <property name="url" value="jdbc:mysql:///ecobee" />
>>   <property name="username" value="XXX" />
>>   <property name="password" value="YYY" />
>>   <property name="initialSize" value="10" />
>>   <property name="maxActive" value="100" />
>>   <property name="maxIdle" value="16" />
>>   <property name="maxWait" value="2000" />
>>  </bean>
>>
>>  <bean id="sqlMapClient"
>> class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
>>   <property name="dataSource" ref="dataSource" />
>>   <property name="configLocation" ref="mapConfig" />
>>  </bean>
>>
>>
>>
>>
>>  ------------------------------
>> *From:* bala r [mailto:balar4u@gmail.com]
>> *Sent:* Thursday, August 21, 2008 4:10 PM
>> *To:* user-java@ibatis.apache.org
>> *Subject:* Spring with IBatis and Transaction Manager Helps.
>>
>>  Hi,
>>
>> I have to implement TransacationManager in my module using Spring with
>> Ibatis.
>>
>> Here is my requirments.
>>
>> TransacationProcessor  -
>>   --Open Transacation
>>   --Call LoopProcessor(process multiple files )
>>            --- Call DatabaseProcessor
>>                       -- Call SQLMqpClient Insert/update/delete.
>>            -- Call OtherProcessor do Work.
>>   --All Success then Committransaction.
>>   -- If fails rollbackTransacation.
>>   --End Transaction.
>>
>> Any documents for handling Spring and Ibaris or any examples i can get
>> from any source?
>> I tried google Spring with Ibatis transaction but couldnt find any much
>> information.
>>
>> Thanks
>> bala.
>>
>
>

Re: Spring with IBatis and Transaction Manager Helps.

Posted by bala r <ba...@gmail.com>.
Hi Brian,

Thank you so much.. I will try your config.. I want to handle the
transaction in the Service layer not in DAO.
I will implement the same config and call the AOP in the service layer.

Thanks
Bala.

On Fri, Aug 22, 2008 at 7:36 AM, Brian Parkinson <pa...@avaning.com> wrote:

>  Hi Bala:
>
> I am using Spring with iBatis with transations. Below is the config that I
> am using - note the use of the spring tx:* AOP transaction injection. There
> are docs in the spring project related to how to set this up (mine below is
> pretty much a copy of that example).
>
> Hope it helps.
>
> Brian Parkinson.
>
> --- x8 snip
>
>  SqlMapConfig contains:
>
>  <transactionManager type="EXTERNAL">
>   <dataSource type="DBCP">
>   </dataSource>
>  </transactionManager>
>
>  Spring transactions:
>
>  <bean id="txManager"
> class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
>   <property name="dataSource" ref="dataSource"/>
>  </bean>
>
>  <tx:advice id="txAdvice" transaction-manager="txManager">
>   <tx:attributes>
>    <tx:method name="get*" read-only="true" />
>    <tx:method name="*" />
>   </tx:attributes>
>  </tx:advice>
>
>  <aop:config>
>   <aop:pointcut id="daoServiceOperation" expression="execution(*
> com.ecobee.foundation.dao.ibatis.*.*(..))" />
>   <aop:advisor advice-ref="txAdvice" pointcut-ref="daoServiceOperation" />
>  </aop:config>
>
> Spring datasource:
>
>  <bean id="mapConfig"
> class="org.springframework.core.io.ClassPathResource">
>   <constructor-arg>
>    <value>com/ecobee/foundation/dao/ibatis/SqlMapConfig.xml</value>
>   </constructor-arg>
>  </bean>
>
>  <bean id="dataSource"
> class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
>   <property name="targetDataSource">
>    <ref local="dataSourceImpl"/>
>   </property>
>  </bean>
>
>  <bean id="dataSourceImpl" class="org.apache.commons.dbcp.BasicDataSource"
> destroy-method="close">
>   <property name="driverClassName" value="com.mysql.jdbc.Driver" />
>   <property name="url" value="jdbc:mysql:///ecobee" />
>   <property name="username" value="XXX" />
>   <property name="password" value="YYY" />
>   <property name="initialSize" value="10" />
>   <property name="maxActive" value="100" />
>   <property name="maxIdle" value="16" />
>   <property name="maxWait" value="2000" />
>  </bean>
>
>  <bean id="sqlMapClient"
> class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
>   <property name="dataSource" ref="dataSource" />
>   <property name="configLocation" ref="mapConfig" />
>  </bean>
>
>
>
>
>  ------------------------------
> *From:* bala r [mailto:balar4u@gmail.com]
> *Sent:* Thursday, August 21, 2008 4:10 PM
> *To:* user-java@ibatis.apache.org
> *Subject:* Spring with IBatis and Transaction Manager Helps.
>
>  Hi,
>
> I have to implement TransacationManager in my module using Spring with
> Ibatis.
>
> Here is my requirments.
>
> TransacationProcessor  -
>   --Open Transacation
>   --Call LoopProcessor(process multiple files )
>            --- Call DatabaseProcessor
>                       -- Call SQLMqpClient Insert/update/delete.
>            -- Call OtherProcessor do Work.
>   --All Success then Committransaction.
>   -- If fails rollbackTransacation.
>   --End Transaction.
>
> Any documents for handling Spring and Ibaris or any examples i can get from
> any source?
> I tried google Spring with Ibatis transaction but couldnt find any much
> information.
>
> Thanks
> bala.
>

RE: Spring with IBatis and Transaction Manager Helps.

Posted by Brian Parkinson <pa...@avaning.com>.
Hi Bala:
 
I am using Spring with iBatis with transations. Below is the config that
I am using - note the use of the spring tx:* AOP transaction injection.
There are docs in the spring project related to how to set this up (mine
below is pretty much a copy of that example).
 
Hope it helps.
 
Brian Parkinson.
 
--- x8 snip
 
SqlMapConfig contains:
 
 <transactionManager type="EXTERNAL">
  <dataSource type="DBCP">
  </dataSource>
 </transactionManager>
 
Spring transactions:
 
 <bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
>
  <property name="dataSource" ref="dataSource"/>
 </bean>
 
 <tx:advice id="txAdvice" transaction-manager="txManager">
  <tx:attributes>
   <tx:method name="get*" read-only="true" />
   <tx:method name="*" />
  </tx:attributes>
 </tx:advice>
 
 <aop:config>
  <aop:pointcut id="daoServiceOperation" expression="execution(*
com.ecobee.foundation.dao.ibatis.*.*(..))" />
  <aop:advisor advice-ref="txAdvice" pointcut-ref="daoServiceOperation"
/>
 </aop:config>
 
Spring datasource:
 
 <bean id="mapConfig"
class="org.springframework.core.io.ClassPathResource">
  <constructor-arg>
   <value>com/ecobee/foundation/dao/ibatis/SqlMapConfig.xml</value>
  </constructor-arg>
 </bean>
 
 <bean id="dataSource"
class="org.springframework.jdbc.datasource.TransactionAwareDataSourcePro
xy">
  <property name="targetDataSource">
   <ref local="dataSourceImpl"/>
  </property>
 </bean>
 
 <bean id="dataSourceImpl"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  <property name="url" value="jdbc:mysql:///ecobee" />
  <property name="username" value="XXX" />
  <property name="password" value="YYY" /> 
  <property name="initialSize" value="10" />
  <property name="maxActive" value="100" /> 
  <property name="maxIdle" value="16" />
  <property name="maxWait" value="2000" />
 </bean>
 
 <bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  <property name="dataSource" ref="dataSource" />
  <property name="configLocation" ref="mapConfig" />
 </bean>
 
 
 

________________________________

From: bala r [mailto:balar4u@gmail.com] 
Sent: Thursday, August 21, 2008 4:10 PM
To: user-java@ibatis.apache.org
Subject: Spring with IBatis and Transaction Manager Helps.


Hi,

I have to implement TransacationManager in my module using Spring with
Ibatis.

Here is my requirments.

TransacationProcessor  - 
  --Open Transacation
  --Call LoopProcessor(process multiple files )
           --- Call DatabaseProcessor
                      -- Call SQLMqpClient Insert/update/delete.
           -- Call OtherProcessor do Work.
  --All Success then Committransaction.
  -- If fails rollbackTransacation.
  --End Transaction.

Any documents for handling Spring and Ibaris or any examples i can get
from any source? 
I tried google Spring with Ibatis transaction but couldnt find any much
information.

Thanks
bala.