在异常时没有发生会话回滚

时间:2014-01-18 05:17:43

标签: java hibernate

我有一个实现下面描述的事务的方法。在这个方法中我调用了另一个具有会话实现的方法。但是如果父方法中发生异常,则不会回滚由子方法修改的更改

public void saveOrUpdateApplicantDLBLPageThree(Applicant applicant,DealerBackLogBo dealerBackLogBo,String...qCode) {
    // TODO Auto-generated method stub
    Session session=getHibernateTemplate().getSessionFactory().openSession();
    Transaction tx = null;
    try {
        tx=session.beginTransaction();
        if(dealerBackLogBo!=null){
            Set<LocationLocalbody> oldLocationLocalbodies=new HashSet<LocationLocalbody>();
            oldLocationLocalbodies=dealerBackLogBo.getOldLocationLocalbodies();

            for (Iterator<LocationLocalbody> iterator = oldLocationLocalbodies.iterator(); iterator.hasNext();) {
                LocationLocalbody locationLocalbody = (LocationLocalbody) iterator.next();
                session.delete(locationLocalbody);  
                session.flush();
                session.clear();
                } 
            if(qCode.length>0){
                updateQuarryStatus(qCode[0]);
                }
            }
        session.saveOrUpdate(applicant);
        session.flush();
        session.clear();
        tx.commit();
        } catch (HibernateException e) {
            // TODO: handle exception
            if (tx!=null) tx.rollback();
            e.printStackTrace();
            }finally{
                session.close();
                }

}

子方法'updateQuarryStatus()'看起来像这样

    public void updateQuarryStatus(String qcode) {
    // TODO Auto-generated method stub      
    Session session=getSession();   
    @SuppressWarnings("rawtypes")
    List list=getHibernateTemplate().find("select max(applicationId) from Application where quarryCode=? and applicationNo='current'",qcode);
    if(list.size()>0){
        String applicationId=list.get(0).toString();        

        Application application=(Application) session.get(Application.class, Long.parseLong(applicationId));
        application.setApplicationNo(null);
        try{
            session.update(application); 
            session.flush();
            session.clear();
            }catch(Exception e){}           
    }

}

我无法识别bug。所以我邀请你的建议来解决这个问题

0 个答案:

没有答案