日期:2014-05-17  浏览次数:20690 次

hibernate联结的子表无法update
这里能取到_evaluatescholarship,然后里面的子表也都取到了,但是更新不上去,不晓得为啥。。。。。用的更新函数是已经写好的

Java code

public String editStuScholarship() {
        String currentTime = TimeGenerator.getCurrentTime();
        try {
            Evaluatescholarship _evaluatescholarship = this.evaluateScholarshipService.findById(evaluatescholarship.getEno());
            if (null == _evaluatescholarship) {
                return "input";
            }
            Stubasicinfo stubasicinfo = _evaluatescholarship.getStubasicinfo();
            Rewardsys rewardsys = _evaluatescholarship.getRewardsys();
            Majorinfo majorinfo = _evaluatescholarship.getStubasicinfo().getMajorinfo();
            stubasicinfo.setStbStuNo(evaluatescholarship.getStubasicinfo().getStbStuNo());
            stubasicinfo.setStbName(evaluatescholarship.getStubasicinfo().getStbName());
            stubasicinfo.setSyear(evaluatescholarship.getStubasicinfo().getSyear());
            majorinfo.setMname(evaluatescholarship.getStubasicinfo().getMajorinfo().getMname());
            rewardsys.setRrank(evaluatescholarship.getRewardsys().getRrank());
            stubasicinfo.setMajorinfo(majorinfo);
            _evaluatescholarship.setStubasicinfo(stubasicinfo);
            _evaluatescholarship.setRewardsys(rewardsys);
            //_evaluatescholarship.setStubasicinfo(stubasicinfo)
            this.evaluateScholarshipService.update(_evaluatescholarship);            
            System.out.println("action getEno = "+id);
            logger.info(currentTime + " 用户【" + evaluatescholarship + "】登录:");
                //ActionContext.getContext().put("allList", _list);        
                if(stuType==1){
                    return "success_master";
                }
                else{
                    return "success_doctor";
                }
        } catch (Exception e) {
//            logger.info(" ******************** Method: [execute] ******************** " + 
//                    "throw an exception,the reason may be username or password is wrong!");
            e.printStackTrace();
            return "input";
        }
    }
    



Java code

    /** 
     * 向数据库更新一条对应于一个业务对象实例的记录 
     * 
     * @param entity 业务对象实例 
     */
    public void update(Object entity) throws DaoException {
        try {
            System.out.println("update sucess");
            getHibernateTemplate().update(entity);
            System.out.println("111");
        } catch (DataAccessException e) {
            System.out.println("update failed"    );
            logger.error("向数据库更新 " + entity.getClass().getName() + " 的记录失败", e);
            throw new DaoException("更新 " + entity.getClass().getName()
                    + " 实例到数据库失败", e);            
        }
    }





------解决方案--------------------
无法更新子表,你的意思是,主表更新成功了,子表没有级联更新?
这样的话,不知道你的关联关系如何设置,级联又如何。