Topic: Hibernate 问题求助

  Print this page

1.Hibernate 问题求助 Copy to clipboard
Posted by: jialichao
Posted on: 2006-10-29 01:01

谁帮我看看这段代码有什么问题呀,我的页面跳转不过去,点击注册以后就是空的.
报这个异常 : javax.servlet.ServletException: null id in entry (don't flush the Session after an exception occurs)

  public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) {
    RegForm regForm = (RegForm) form;

    Session session=HibernateSessionFactory.currentSession();
    Transaction ts=session.beginTransaction();   
 
    String name=regForm.getUsername(); //从jsp页面得到用户名和密码
    String pas=regForm.getPassword();  

    String str="from MyUsers where userName=?"; //查找用户是不是存在
    Query query=session.createQuery(str);
    query.setString(0,name);
    List list=(ArrayList) query.list();

    if(list.size()<=0){ //不存在的话就写入数据库
      MyUsers users=new MyUsers();
      users.setNames(name);
      users.setPassWord(pas);
      session.save(users);    
      ts.commit();  
      return mapping.findForward("success1"); //跳转到注册好的页面
    }else{
     return mapping.findForward("defeat");
    }
  }

2.Re:Hibernate 问题求助 [Re: jialichao] Copy to clipboard
Posted by: YuLimin
Posted on: 2006-10-30 20:47

null id in entry (don't flush the Session after an exception occurs)

MyUsers的ID生成规则是什么?把.hbm.xml内容放出来看看。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923