|
我把程序贴上来大家看看。
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
|