OSGi框架下使用iBATIS事务rollback不生效

关键词:osgi ibatis rollback autocommit

环境:
osgi框架下使用spring和iBATIS做数据库操作,其中事务是使用iBATIS的实现。

SqlMapClient sqlmapClient = this.getSqlMapClient();
try
{
sqlmapClient.startTransaction();
updateUsingChecks(id);
deleteChecks(id);
sqlmapClient.commitTransaction();
sqlmapClient.endTransaction();
}
catch ( Exception e)
{
try
{
sqlmapClient.endTransaction();
}
catch ( SQLException e1)
{
}
return false;
}


实现本身没有错,但就是无法正常执行事务回退。框架这钟东西出问题很难排查,尤其是我这种对框架本身就不太熟悉的。无奈看源码,发现其事务实现类不同:


JdbcTransaction

ExternalTransaction


OSGI框架下是ExternalTransaction实现类,下面是该方法的注释:


* Set properties to be passed to the TransactionConfig instance used
* by this SqlMapClient. Supported properties depend on the concrete
* TransactionConfig implementation used:
* <p><ul>
* <li><b>ExternalTransactionConfig</b> supports "DefaultAutoCommit"
* (default: false) and "SetAutoCommitAllowed" (default: true).
* Note that Spring uses SetAutoCommitAllowed = false as default,
* in contrast to the iBATIS default, to always keep the original
* autoCommit value as provided by the connection pool.
* <li><b>JdbcTransactionConfig</b> does not supported any properties.
* <li><b>JtaTransactionConfig</b> supports "UserTransaction"
* (no default), specifying the JNDI location of the JTA UserTransaction
* (usually "java:comp/UserTransaction").
* </ul>


NND,原来iBATIS默认是自动提交,且不能修改。。。无奈了不知道哪些大牛出于啥目的。浪费半天时间,修改为spring事务处理也就是JdbcTransaction实现类,成功。。。

PS:不要说设置autoCommit为false,我试过无论怎么设置也不生效,不要问为啥,我也不知道。你要知道一定告诉我。


以上,希望对大家有用吧。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值