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/26 20:32:36 UTC
Programmatic Transaction for Spring and Ibatis SqlMapClient
Hi,
I am using Spring Programmatic transaction in the service layer and service
layer calls IBatisDAO(sqlMapClientTemplate) to insert/update.
Transaction Rollback and commit works fine.
But if i introduce any new layer between Service and IBatisDAO the
transaction rollback is not working...
Here is the code sniplet.
DefaultTransactionDefinition def = new
DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = txManager.getTransaction(def);
try{
ibatisDAO.process(dataMap, processorId); //This is direct
call to ibatisDAO and transaction process works fine.
//ibatisDAOProcessor.process(dataMap); // This is another
layer between Service and IbatisDAO.transaction rollback doesnt work.
}catch(MultipleErrorsException me){
txManager.commit(status);
}
txManager.commit(status);
Spring config
------------------------------
<bean name="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref bean="inetDs"/>
</property>
</bean>
<bean id="sqlMap"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>sqlMapConfig.xml</value>
</property>
<property name="dataSource">
<ref bean="datasource"/>
</property>
<property name="useTransactionAwareDataSource">
<value>true</value>
</property>
<property name="transactionConfigClass">
<value>com.ibatis.sqlmap.engine.transaction.external.ExternalTransactionConfig</value>
</property>
<property name="transactionConfigProperties">
<props>
<prop key="DefaultAutoCommit">false</prop>
</props>
</property>
</bean>
Thanks in Advance..
Re: Programmatic Transaction for Spring and Ibatis SqlMapClient
Posted by bala r <ba...@gmail.com>.
Hi,
Passing TransactionStatus to txManager.commit(TransactionStatus), if any
runtime exception occurs it said rollbackOnly to true.
As i mentioned Rollback works fine if i call IbatisDAO directly in the
ServiceLayer(TransactionProcessor), But i put one more Layer
IbatisDAOProcessor between Service and IBatisDAO then the transaction
rollback doesn't work..
I also tried the following code but rollback is not happening.....
}catch( MultipleErrorsException me){
status.setRollBackOnly();
txManager.commit(status);
}
I guess problem here is when i call a additional layer between service and
ibatisDAO, new transaction is created in the addional layer and the commits
happening right after the IBatisDAO call.
How do i foce to use the same transaction which i created in ServiceLayer to
IbatisDAO?
Thanks
Bala
On Tue, Aug 26, 2008 at 9:00 PM, Richard Yee <ry...@cruzio.com> wrote:
> What is this code doing?
>
> }catch(MultipleErrorsException me){
> txManager.commit(status);
> }
>
> Aren't you committing when an exception occurs?
>
> -R
>
>
>
> bala r wrote:
>
>> Hi,
>>
>> I am using Spring Programmatic transaction in the service layer and
>> service layer calls IBatisDAO(sqlMapClientTemplate) to insert/update.
>> Transaction Rollback and commit works fine.
>> But if i introduce any new layer between Service and IBatisDAO the
>> transaction rollback is not working...
>>
>> Here is the code sniplet.
>>
>> DefaultTransactionDefinition def = new
>> DefaultTransactionDefinition();
>>
>> def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
>> TransactionStatus status = txManager.getTransaction(def);
>> try{
>> ibatisDAO.process(dataMap, processorId); //This is direct
>> call to ibatisDAO and transaction process works fine.
>> //ibatisDAOProcessor.process(dataMap); // This is another
>> layer between Service and IbatisDAO.transaction rollback doesnt work.
>> }catch(MultipleErrorsException me){
>> txManager.commit(status);
>> }
>> txManager.commit(status);
>>
>>
>> Spring config
>> ------------------------------
>> <bean name="txManager"
>>
>> class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
>> <property name="dataSource">
>> <ref bean="inetDs"/>
>> </property>
>> </bean>
>>
>> <bean id="sqlMap"
>> class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
>> <property name="configLocation">
>> <value>sqlMapConfig.xml</value>
>> </property>
>> <property name="dataSource">
>> <ref bean="datasource"/>
>> </property>
>> <property name="useTransactionAwareDataSource">
>> <value>true</value>
>> </property>
>> <property name="transactionConfigClass">
>>
>> <value>com.ibatis.sqlmap.engine.transaction.external.ExternalTransactionConfig</value>
>> </property>
>> <property name="transactionConfigProperties">
>> <props>
>> <prop key="DefaultAutoCommit">false</prop>
>> </props>
>> </property>
>> </bean>
>>
>> Thanks in Advance..
>>
>
>
Re: Programmatic Transaction for Spring and Ibatis SqlMapClient
Posted by Richard Yee <ry...@cruzio.com>.
What is this code doing?
}catch(MultipleErrorsException me){
txManager.commit(status);
}
Aren't you committing when an exception occurs?
-R
bala r wrote:
> Hi,
>
> I am using Spring Programmatic transaction in the service layer and
> service layer calls IBatisDAO(sqlMapClientTemplate) to insert/update.
> Transaction Rollback and commit works fine.
> But if i introduce any new layer between Service and IBatisDAO the
> transaction rollback is not working...
>
> Here is the code sniplet.
>
> DefaultTransactionDefinition def = new
> DefaultTransactionDefinition();
>
> def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
> TransactionStatus status = txManager.getTransaction(def);
> try{
> ibatisDAO.process(dataMap, processorId); //This is
> direct call to ibatisDAO and transaction process works fine.
> //ibatisDAOProcessor.process(dataMap); // This is
> another layer between Service and IbatisDAO.transaction rollback
> doesnt work.
>
> }catch(MultipleErrorsException me){
> txManager.commit(status);
> }
> txManager.commit(status);
>
>
> Spring config
> ------------------------------
> <bean name="txManager"
>
> class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
> <property name="dataSource">
> <ref bean="inetDs"/>
> </property>
> </bean>
>
> <bean id="sqlMap"
> class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
> <property name="configLocation">
> <value>sqlMapConfig.xml</value>
> </property>
> <property name="dataSource">
> <ref bean="datasource"/>
> </property>
> <property name="useTransactionAwareDataSource">
> <value>true</value>
> </property>
> <property name="transactionConfigClass">
>
> <value>com.ibatis.sqlmap.engine.transaction.external.ExternalTransactionConfig</value>
> </property>
> <property name="transactionConfigProperties">
> <props>
> <prop key="DefaultAutoCommit">false</prop>
> </props>
> </property>
> </bean>
>
> Thanks in Advance..