大家帮帮忙..~public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
 int id = Integer.parseInt(request.getParameter("id"));
SelfProjectActionForm selfProjectActionForm=(SelfProjectActionForm)form;
String labadvice=new String(selfProjectActionForm.getLabadvice().getBytes("ISO-8859-1"),"GB2312");
String tutoradvice=new String(selfProjectActionForm.getTutoradvice().getBytes("ISO-8859-1"),"GB2312");
selfDao=this.getSelfProjectDAO();
Selfproject selfproject=selfDao.getSelfProjectByID(id);
    selfproject.setTutoradvice(tutoradvice);
    selfproject.setLabadvice(labadvice);
 try{
 if(!selfDao.updateSelfProject(selfproject)){
 return mapping.findForward("failure");
 }else{
 return mapping.findForward("success");  
 } 
 }catch(HibernateException e){
e.printStackTrace();
return mapping.findForward("failure");
 }
}
  其中呢 selfproject是有20个字段的,先前的A页面先插入15个字段,当时未插入的为空,
然后到现在的B页面,显示那15个字段,并提供另外2个字段的输入框,即Tutoradvice和Labadvice..
然后提交到 贴出代码的 Action里, 
可以执行到else{
 return mapping.findForward("success");  也就是说selfDao.updateSelfProject(selfproject)是已经成功执行了 但是 数据库中 tutoradvice 和 labadvice仍然为空. 不知道是怎么回事呢? 好像是没有分数了 不好意思啊 麻烦大家给看看啊  拜托了......

解决方案 »

  1.   

    首先,最基本的  看一下你的程序连接数据库和你自己查看的数据库是不是一个数据库(还真别小看这个问题)如果不是上述,那么用调试看当你执行updateSelfProject方法时,selfproject的数据状态,在该对象中是否有两个值如果对象的值也没问题,看一下你updateSelfProject()方法执行时,最后有没有提交数据库,也就是有没有commit();有时候如果你吧事务设置了手动提交,但是有没有commit数据库是不会有值的。我才疏学浅,只能想到这么多了
      

  2.   

    HIBERNATE是緩存的,只有你手動COMMIT一個TRANSACTION或者SESSION決定的時候才一次性把緩存里的數據寫入,如果你單步DEBUG的話,加上TRANS.BEGIN()和TRANS.COMMIT()就可以看數據庫了
      

  3.   

    public boolean updateSelfProject(Selfproject selfproject){
    try{Session s=HibernateUtil.currentSession();
           HibernateUtil.beginTransaction();
       s.update(selfproject);
       HibernateUtil.commitTransaction();
       HibernateUtil.closeSession();
       return true;
    }catch(HibernateException e){
    log.fatal(e);
    }
    return false;
       

    }这个代码 看着也没问题啊...还是不行啊 哭了..
      

  4.   

    麻烦格式化代码先, 这个谁愿意看啊,你去看下控制台打印的sql语句,就能看到是不是更新了
      

  5.   

    public class TeacherTest {
    @Test
    public void update(){
    Session session =  HibernateUitl.getSessionFactory().getCurrentSession();
    session.beginTransaction();
    Teacher t = (Teacher) session.get(Teacher.class, 3);
    t.setName("yangtb2");
    session.update(t);

    session.getTransaction().commit();
    }
    }
      

  6.   

    在你
    updateSelfProject
    这个方法加上事务(如果是hibernate)
    如  LeeHomWong 6楼所说的那样试!如果是jdbc的默认如果成功的话会自动提交 的
      

  7.   

    你这个问题没问题吗?你开启的是HibernateUtil里面的事物,对你更新语句根本没作用,应该开启session中事务,还有catach的时候要throw e;
      

  8.   

    大家好啊  我还是不会弄  好像我HibernateUtil是不是 写的不完整呢?实在麻烦各位了  希望 leehom能再进来啊..HibernateUtil.javapackage com.sdut.dao.hibernate;
    import org.hibernate.HibernateException;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.cfg.Configuration;public class HibernateUtil {
      private static final SessionFactory sessionFactory;
      
      static {
      try {//创建SessionFactory
      sessionFactory = new Configuration().configure().buildSessionFactory();
      }catch(Throwable ex){
      ex.printStackTrace();
      System.out.println("Initial SessionFactory creation failed.");
      throw new ExceptionInInitializerError(ex);
      }
      }
      public static final ThreadLocal<Session> tLocalsess=new ThreadLocal<Session>();
      public static final ThreadLocal<Transaction> tLocaltx=new ThreadLocal<Transaction>();
      //取得session
      public static Session currentSession(){
      Session session=(Session)tLocalsess.get();
      //打开一个新的session,如果当前不可用
      try{if(session==null||!session.isOpen()){
      session=openSession();
      tLocalsess.set(session);
      }
      }catch(HibernateException e){
      e.printStackTrace();
      }
     return session; 
      }
      //关闭session
      public static void closeSession(){
      Session session = (Session) tLocalsess.get();
      tLocalsess.set(null);
      try{if(session!=null&&session.isOpen()){
      session.close();
      }
      }catch(HibernateException e){}
      
      }
      //开始事务
      public static void beginTransaction(){
      //声明Transaction类型对象x,并赋初值
      Transaction tx=(Transaction)tLocaltx.get();
     try{
     if(tx==null){
     tx=currentSession().beginTransaction();
     tLocaltx.set(tx);
     }
     }catch(HibernateException e) {
     //抛出异常
     }
      }
      //关闭事务
      public static void commitTransaction(){
      Transaction tx=(Transaction) tLocaltx.get();
      try{if(tx!=null&&!tx.wasCommitted()&&!tx.wasRolledBack())
      tx.commit();
      tLocaltx.set(null);
      System.out.println("commit tx");
      }catch(HibernateException e){}
      }
      //事务回滚
      public static void rollbackTransaction(){
      Transaction tx=(Transaction) tLocaltx.get();
      try {
      tLocaltx.set(null);
      if(tx!=null&&!tx.wasCommitted()&&!tx.wasRolledBack()){
      tx.rollback();
      }
      }catch(HibernateException e){}
      }
      private static Session openSession()throws HibernateException{
      return getSessionFactory().openSession();
      }
      private static SessionFactory getSessionFactory() throws HibernateException{
      return sessionFactory;
      }
      }  您看 有问题吗 没有的话 我在去仔细看看Hibernate教材里关于这部分的内容