代码之家  ›  专栏  ›  技术社区  ›  Am1rr3zA

休眠多级事务

  •  0
  • Am1rr3zA  · 技术社区  · 16 年前

    让我用代码解释一下

    public void changeBranch(Branch branch) throws DatabaseException {
    //some code
                humanDao.update(he);
                superBranchUsername = branch.getFatherUsername();
                int superBranchId = branchDao.getBranchIdByUserName(superBranchUsername);
                BranchEntity superBranch = branchDao.load(superBranchId);
                BranchEntity be = new BranchEntity();
                setBranchEntity(be, he, pkId, bname, confirmed, level, studentCount, uname, superBranch);
                branchDao.update(be);   // update kardane jadvale Branch va Set kardane Human motenazer be on
    //some code
    }
    

    两者 humanDao.update(he); branchDao.update(be); 但是我希望这段代码(上面写的)也能在事务中运行!!我怎样才能进入冬眠状态呢?

    3 回复  |  直到 9 年前
        1
  •  2
  •   duffymo    16 年前

    DAO不应该处理事务,原因正是您发现的:它们不知道何时属于更大事务的一部分。

    如果你正在使用 Spring 声明性事务,您将拥有一个服务层,它将为DAO和处理所有事务创建事务上下文。我建议你做那样的事。

        2
  •  1
  •   Mitch Wheat    16 年前
        3
  •  0
  •   Am1rr3zA    16 年前

    changeBranch(Branch branch)

    推荐文章