%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: entity class not found: User
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:99)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:168)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:123)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at com.gs.MyCon.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31)
at com.gs.dao.UserDao.login(UserDao.java:13)
at com.gs.struts.action.UserAction.login(UserAction.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: User
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:96)
... 35 more
这是DAO层的,
public User login(String username,String password){
Session session = HibernateSessionFactory.getSession();
session.beginTransaction();
Query query = session.createQuery("from User where username = ? and password = ?");
query.setString(0, username);
query.setString(1, password);
List list = query.list();
User u = null;
if(list.size() > 0){
u = (User)list.get(0);
}
session.getTransaction().commit();
HibernateSessionFactory.closeSession();
return u;
}ACTION
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserForm userForm = (UserForm) form;// TODO Auto-generated method stub
UserDao ud = new UserDao();
User u = ud.login(userForm.getUsername(), userForm.getPassword());
String url = "error";
if(u != null){
//把登陆的对象放入session中
request.getSession().setAttribute("u", u);
url = "success";
}
return mapping.findForward(url);
}

解决方案 »

  1.   


    Error Creating SessionFactoryorg.hibernate.MappingException: entity class not found: UserCaused by: java.lang.ClassNotFoundException: User你的映射文件有没有映射User?
      

  2.   

    <hibernate-mapping>
        <class name="User" table="T_USER" schema="DEV"> 
    貌似是User没找到,写上你完整的包名吧。
      

  3.   

    找不到user映射的实体类.
    你看一下hibernate对user映射的user类有吗
      

  4.   

    package com.gs.entity;
    // default packageimport java.util.HashSet;
    import java.util.Set;
    /**
     * User entity. @author MyEclipse Persistence Tools
     */public class User  implements java.io.Serializable {
        // Fields         private Long id;
         private Tbranch TBranch;
         private String username;
         private String password;
         private String staffName;
         private String workTime;
         private String email;
         private String phone;
         private String status;
         private String isImmediately;
         private Long ftpId;
         private Set TUserRoles = new HashSet(0);
         private Set TAuthorizes = new HashSet(0);
         private Set THistoryLogs = new HashSet(0);
         private Set TPacks = new HashSet(0);
         private Set TLogs = new HashSet(0);
        // Constructors    /** default constructor */
        public User() {
        } /** minimal constructor */
        public User(Tbranch TBranch, String username, String status) {
            this.TBranch = TBranch;
            this.username = username;
            this.status = status;
        }
        
        /** full constructor */
        public User(Tbranch TBranch, String username, String password, String staffName, String workTime, String email, String phone, String status, String isImmediately, Long ftpId, Set TUserRoles, Set TAuthorizes, Set THistoryLogs, Set TPacks, Set TLogs) {
            this.TBranch = TBranch;
            this.username = username;
            this.password = password;
            this.staffName = staffName;
            this.workTime = workTime;
            this.email = email;
            this.phone = phone;
            this.status = status;
            this.isImmediately = isImmediately;
            this.ftpId = ftpId;
            this.TUserRoles = TUserRoles;
            this.TAuthorizes = TAuthorizes;
            this.THistoryLogs = THistoryLogs;
            this.TPacks = TPacks;
            this.TLogs = TLogs;
        }   
        // Property accessors    public Long getId() {
            return this.id;
        }
        
        public void setId(Long id) {
            this.id = id;
        }    public Tbranch getTBranch() {
            return this.TBranch;
        }
        
        public void setTBranch(Tbranch TBranch) {
            this.TBranch = TBranch;
        }    public String getUsername() {
            return this.username;
        }
        
        public void setUsername(String username) {
            this.username = username;
        }    public String getPassword() {
            return this.password;
        }
        
        public void setPassword(String password) {
            this.password = password;
        }    public String getStaffName() {
            return this.staffName;
        }
        
        public void setStaffName(String staffName) {
            this.staffName = staffName;
        }    public String getWorkTime() {
            return this.workTime;
        }
        
        public void setWorkTime(String workTime) {
            this.workTime = workTime;
        }    public String getEmail() {
            return this.email;
        }
        
        public void setEmail(String email) {
            this.email = email;
        }    public String getPhone() {
            return this.phone;
        }
        
        public void setPhone(String phone) {
            this.phone = phone;
        }    public String getStatus() {
            return this.status;
        }
        
        public void setStatus(String status) {
            this.status = status;
        }    public String getIsImmediately() {
            return this.isImmediately;
        }
        
        public void setIsImmediately(String isImmediately) {
            this.isImmediately = isImmediately;
        }    public Long getFtpId() {
            return this.ftpId;
        }
        
        public void setFtpId(Long ftpId) {
            this.ftpId = ftpId;
        }    public Set getTUserRoles() {
            return this.TUserRoles;
        }
        
        public void setTUserRoles(Set TUserRoles) {
            this.TUserRoles = TUserRoles;
        }    public Set getTAuthorizes() {
            return this.TAuthorizes;
        }
        
        public void setTAuthorizes(Set TAuthorizes) {
            this.TAuthorizes = TAuthorizes;
        }    public Set getTHistoryLogs() {
            return this.THistoryLogs;
        }
        
        public void setTHistoryLogs(Set THistoryLogs) {
            this.THistoryLogs = THistoryLogs;
        }    public Set getTPacks() {
            return this.TPacks;
        }
        
        public void setTPacks(Set TPacks) {
            this.TPacks = TPacks;
        }    public Set getTLogs() {
            return this.TLogs;
        }
        
        public void setTLogs(Set TLogs) {
            this.TLogs = TLogs;
        }
       
    }
      

  5.   

    <class name="com.gs.entiy.User"  如果还有错, 那看看错误信息变了没
      

  6.   

    恩,行了,配置文件的问题,但现在action中的
    User u = ud.login(userForm.getUsername(), userForm.getPassword()); 
    u是null,是怎么回事啊,这是DAO层的, 
    public User login(String username,String password){ 
    Session session = HibernateSessionFactory.getSession(); 
    session.beginTransaction(); 
    Query query = session.createQuery("from User where username = ? and password = ?"); 
    query.setString(0, username); 
    query.setString(1, password); 
    List list = query.list(); 
    User u = null; 
    if(list.size() > 0){ 
    u = (User)list.get(0); 

    session.getTransaction().commit(); 
    HibernateSessionFactory.closeSession(); 
    return u; 

      

  7.   

    System.out.println("username is :"+username+" .password is :"+password);
    然后再去数据库核对有没有记录
      

  8.   

    username 有值,password是null