期货交易自动化论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 37|回复: 0

tx.commit失败 - 金融行业 - ITPUB论坛-专业的IT技术社区

[复制链接] |主动推送

285万

主题

285万

帖子

855万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
8553710
发表于 2022-9-11 08:15:57 | 显示全部楼层 |阅读模式
我把程序贴上来大家看看。
private BOPrimaryKeyInfo getNextPrimaryKey(int entity, int range, String tableName, String keyColName) throws DAOException {
Vector Object param = new Vector Object
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。谁能帮忙看看吗
executeUpdate(UPDATE_PRIMARY_KEY_TABLE, param, tx);
这句就已经有错误了,已经调用过rollback了
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吗

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

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

本版积分规则

QQ|Archiver|手机版|小黑屋|期货交易自动化论坛

GMT+8, 2025-8-26 18:15 , Processed in 0.084462 second(s), 28 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表