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,我试过无论怎么设置也不生效,不要问为啥,我也不知道。你要知道一定告诉我。


以上,希望对大家有用吧。

你可能感兴趣的:(spring,html,框架,ibatis,osgi)