ITPub博客

首页 > Linux操作系统 > Linux操作系统 > tx.commit失败

tx.commit失败

原创 Linux操作系统 作者:yuming7498 时间:2011-11-24 14:20:49 0 删除 编辑
我把程序贴上来大家看看。
  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。谁能帮忙看看吗



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22542623/viewspace-711927/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2011-08-16

  • 博文量
    2
  • 访问量
    1606