tx.commit失败

[复制链接]
查看11 | 回复2 | 2011-2-18 11:43:36 | 显示全部楼层 |阅读模式
我把程序贴上来大家看看。
private BOPrimaryKeyInfo getNextPrimaryKey(int entity, int range, String tableName, String keyColName) throws DAOException {
Vector param = new Vector(5);
param.addElement(new Integer(entity));
if (range < 0)
throw new RuntimeException("Can't specify a negative range : " + range);
int nextPrimaryKey = 1;
Transaction tx = null;
DAOResult rs = null;
try {
if (tm == null) {
logger.debug("tm is null");
tx = TransactionManager.getTransaction();
tx.begin();
} else {
logger.debug("tm is not null");
tx = TransactionManager.getTxTransaction();
}
logger.debug("before rs");
rs = this.executeQuery(SELECT_AND_LOCK_PRIMARY_KEY_TABLE, param, tx);
logger.debug("after rs");
if (rs.next()) {
nextPrimaryKey = rs.getInt(1);
if (!rs.wasNull()) {
param.removeAllElements();
int newNextPrimaryKey = nextPrimaryKey + range;
param.addElement(new Integer(newNextPrimaryKey));
param.addElement(new Integer(entity));
logger.debug("before update");
executeUpdate(UPDATE_PRIMARY_KEY_TABLE, param, tx);
logger.debug("after update");
if (tm == null)
tx.commit();
logger.debug("before return BOPrimaryKeyInfo entity_key");
return new BOPrimaryKeyInfo(entity, tableName, keyColName, nextPrimaryKey);
} else {
throw new DAOException("error happened when try to get primary key range is available");
}
}
} catch (Exception ex) {
if (tm == null && tx != null)
tx.rollback();
throw new DAOException("error happened when try to update primary key range is new " + ex);
} finally {
if (rs != null)
rs.close();
if (tx != null)
tx.close();
}
在UPDATE后tx commit报错了,after update这行日志打出来了,但before return BOPrimaryKeyInfo entity_key这行日志没有打出来。回滚也失败了,日志报Cannot call Connection.rollback in distributed transaction. Transaction Manager will commit the resource manager when the distributed transaction is committed。谁能帮忙看看吗


回复

使用道具 举报

千问 | 2011-2-18 11:43:36 | 显示全部楼层
executeUpdate(UPDATE_PRIMARY_KEY_TABLE, param, tx);
这句就已经有错误了,已经调用过rollback了
回复

使用道具 举报

千问 | 2011-2-18 11:43:36 | 显示全部楼层
cavern1026 发表于 2011-11-25 12:00
executeUpdate(UPDATE_PRIMARY_KEY_TABLE, param, tx);
这句就已经有错误了,已经调用过rollback了

那应该怎么改呢,去掉
catch (Exception ex) {
if (tm == null && tx != null)
tx.rollback();
throw new DAOException("error happened when try to update primary key range is new " + ex);
}
吗,但是去掉后if (tm == null && tx != null)的异常怎么处理,tx.close吗
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行