could not load an entity: ??!!
我用Structs+Hibernate作的一个登录的程序,为什么我登录的时候总是提示我不能载入一个实体啊:could not load an entity: [com.adress.Userlist#4]
我的LogonAction.java程序如下:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.adress.struts.action;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.adress.struts.form.LogonForm;
import com.adress.Userlist;
import com.adress.HibernateSessionFactory;
/**
* MyEclipse Struts
* Creation date: 01-18-2007
*
* XDoclet definition:
* @struts.action path="/logon" name="logonForm" input="/logon.jsp" scope="request" validate="true"
*/
public class LogonAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LogonForm logonForm = (LogonForm) form;// TODO Auto-generated method stub
String userName=request.getParameter("userName");
String userPwd=request.getParameter("userPwd");
String mUserPwd=null;
Userlist ul=null;
Session session=HibernateSessionFactory.getSession();
Transaction tx=session.beginTransaction();
Query query=session.createQuery(
"select u from Userlist as u where username='"+userName+"'");
try
{
Iterator it=query.iterate();
ul=(Userlist)it.next();
mUserPwd=ul.getUserpwd();
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
tx.commit();
// session.close();
HibernateSessionFactory.closeSession();
if(mUserPwd.equals(userPwd))
{
return (mapping.findForward("gotomain"));
}
else
{
return (mapping.findForward("rLogon"));
}
}
}