这是hibernate翻转机制产生的save方法,我在service方法中调用时,没有报错,但是却不能将数据保存在数据库,不知道为什么

解决方案 »

  1.   

    public void save(Homeworkinfo transientInstance) {
    log.debug("saving Homeworkinfo instance");
    try {
    getSession().save(transientInstance);
    log.debug("save successful");
    } catch (RuntimeException re) {
    log.error("save failed", re);
    System.out.println("error");
    throw re;
    }
    }
      

  2.   

    service方法:
    public class AddhwService { public void addhw(Homeworkinfo hwinfo){

    HomeworkinfoDAO hwdao=new HomeworkinfoDAO();

    List list=hwdao.findByHwId( hwinfo.getHwId());
    System.out.println("size:"+list.size());
    if(list.size()==0){

    hwdao.attachDirty(hwinfo);
    }
    else{
    System.out.println("id 存在");
    }


    }
    action方法:
    public String execute(){

    AddhwService addhw=new AddhwService();
    Homeworkinfo hwinfo=new Homeworkinfo();
    hwinfo.setHwId(hwid);
    hwinfo.setHworktitle(hworktitle);
    hwinfo.setGrade(grade);
    hwinfo.setClassnum(classnum);
    hwinfo.setSubject(subject);
    hwinfo.setDifficultyrate(difficultyrate);
    hwinfo.setFinishdate(finishdate);
    hwinfo.setIsnecessary(isnecessary);
    hwinfo.setWorkinstruct(workinstruct);
    Date date = new Date();
    SimpleDateFormat   sdf  = new SimpleDateFormat("yyyy-MM-dd"); 
    hwinfo.setPromudate(sdf.format(date));

    addhw.addhw(hwinfo);   
    return "addhwsuccess";
    }
    运行时候没有报错,直接跳转下个页面,但是数据库中无数据,好愁人,请高手帮忙!
    不知道是不是跟翻转产生的merge,attachDirty,attachClean三个方法有关?急求!
      

  3.   

    在service里面需要开启事务吗?不是应该直接调用dao层就行吗?dao层实行自动产生的