将session.saveOrUpdate(login);改为session.save(login);

解决方案 »

  1.   

    Transaction tx=session.beginTransaction();
    这不就开启了吗你帮我该下代码 帖出来我看
      

  2.   

    在这两句login.setUsername(username);
    login.setPassword(password);
    前再加一句:
    login.setId(null);
    试一下.
      

  3.   

    Forumtype ft=new Forumtype();
    DateUtil du=new DateUtil();
    ft.setTitle(title);
    ft.setDel((byte)0);
    ft.setAddtime(du.getCurrentSQLDate());
    Transaction tx=hs.beginTransaction();
    try{
    hs.saveOrUpdate(ft);
    tx.commit();  //主要这里啊
    Criteria crit1=hs.createCriteria(Forumtype.class);
    int pNo = 1;
                Query countSQL = hs.createQuery("select count(*) from Forumtype");
         QueryUtil qu = new QueryUtil();
         Page p = qu.executeQuery(crit1, countSQL, pNo);
            session.setAttribute("p", p);
    return mapping.findForward("s");
    }catch(Exception e){
    e.printStackTrace(System.out);
    tx.rollback();
    }
    return mapping.findForward("s");代码都差不多,你仔细看下
      

  4.   

    SessionFactory sf=new Configuration().configure().buildSessionFactory();
    Session session=sf.openSession();Login login=new Login();
    LoginForm lf=(LoginForm)form;

    String username=lf.getUsername();
    String password=lf.getPassword();

    login.setUsername(username);
    login.setPassword(password);
    Transaction tx=session.beginTransaction();{
    session.saveOrUpdate(login);
    tx.commit();
    session.close();
                         }catch(Exception e)
                               {
    e.printStackTrace(System.out);
    tx.rollback();
    }
    return mapping.findForward("s");
      

  5.   

    其实最根本的是这段程序就不应该放在action里,而是要单独写成一个类,然后在action里调用,这才是最根本的写法也就是MVC的结构写法.
      

  6.   

    sesion hs=HibernateSessionFactory.getSesion();
    你保存只保存在一个session上啊,你要保存到上面的hs里去啊,想你那个的SessionFactory sf=new Configuration().configure().buildSessionFactory();
      

  7.   

    恩 我刚学这东东把他提出来写成个类 Action调用就能添加数据 而不是覆盖数据了吗?大侠能不能给我一个解决方案啊