hibenateutil中的java.lang.noclassdeffounderror

时间:2015-04-06 12:39:00

标签: java hibernate

大家好 我需要你的帮助来解决我的问题,我不知道为什么它不起作用: 发生错误:

  

java.lang.NoClassDefFoundError:无法初始化类   tn.ooredoo.kpi.util.HibernateUtil    - 堆栈跟踪

     

javax.faces.el.E​​valuationException:java.lang.NoClassDefFoundError:   无法初始化类tn.ooredoo.kpi.util.HibernateUtil at   javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:98)     在   com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)     在javax.faces.component.UICommand.broadcast(UICommand.java:311)at   javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781)     在   javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246)     在   com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)     在com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)at   com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)     在javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:585)     在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:310)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)     在java.lang.Thread.run(Thread.java:744)引起:   java.lang.NoClassDefFoundError:无法初始化类   tn.ooredoo.kpi.util.HibernateUtil at   tn.ooredoo.kpi.dao.EmployeDao.getSessionFactory(EmployeDao.java:34)     at tn.ooredoo.kpi.dao.EmployeDao。(EmployeDao.java:30)at at   tn.ooredoo.kpi.controller.LoginCtr.connecter(LoginCtr.java:37)at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:606)at   org.apache.el.parser.AstValue.invoke(AstValue.java:278)at at   org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)     在   com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102)     在   javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:84)     ......还有24个

2 个答案:

答案 0 :(得分:0)

“tn.ooredoo.kpi.util.HibernateUtil” - 无法找到此课程。

这是来自未知类的引用的结果(您没有包含完整错误,所以不可能完全说明发生了什么)

我可以肯定的是,你的类有一个间接引用tn.ooredoo.kpi.util.HibernateUtil并且找不到类 - 它似乎也找不到这个类的一部分在构建或运行期间可能已被排除的库(很可能是运行。)

答案 1 :(得分:0)

public class EmployeDao {

private static final Log log = LogFactory.getLog(EmployeDao.class);

private final SessionFactory sessionFactory = getSessionFactory();

protected SessionFactory getSessionFactory() {
    try {
        return (SessionFactory) HibernateUtil.sessionFactory;
    } catch (Exception e) {
        log.error("Could not locate SessionFactory in JNDI", e);
        throw new IllegalStateException(
                "Could not locate SessionFactory in JNDI");
    }
}

public void persist(Employe transientInstance) {
    log.debug("persisting Employe instance");
    try {
        sessionFactory.getCurrentSession().persist(transientInstance);
        log.debug("persist successful");
    } catch (RuntimeException re) {
        log.error("persist failed", re);
        throw re;
    }
}

private void openTransaction() {
    sessionFactory.getCurrentSession().beginTransaction();
}

private void closeTransaction() {
    sessionFactory.getCurrentSession().getTransaction().commit();
}

public void attachDirty(Employe instance) {
    log.debug("attaching dirty Employe instance");
    try {
        sessionFactory.getCurrentSession().saveOrUpdate(instance);
        log.debug("attach successful");
    } catch (RuntimeException re) {
        log.error("attach failed", re);
        throw re;
    }
}

public void attachClean(Employe instance) {
    log.debug("attaching clean Employe instance");
    try {
        sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
        log.debug("attach successful");
    } catch (RuntimeException re) {
        log.error("attach failed", re);
        throw re;
    }
}

public void delete(Employe persistentInstance) {
    log.debug("deleting Employe instance");
    try {
        sessionFactory.getCurrentSession().delete(persistentInstance);
        log.debug("delete successful");
    } catch (RuntimeException re) {
        log.error("delete failed", re);
        throw re;
    }
}

public Employe merge(Employe detachedInstance) {
    log.debug("merging Employe instance");
    try {
        Employe result = (Employe) sessionFactory.getCurrentSession()
                .merge(detachedInstance);
        log.debug("merge successful");
        return result;
    } catch (RuntimeException re) {
        log.error("merge failed", re);
        throw re;
    }
}

public Employe findById(int id) {
    log.debug("getting Employe instance with id: " + id);
    try {
        openTransaction();
        Employe instance = (Employe) sessionFactory.getCurrentSession()
                .get("tn.ooredoo.kpi.model.Employe", id);
        if (instance == null) {
            log.debug("get successful, no instance found");
        } else {
            log.debug("get successful, instance found");
        }
        return instance;
    } catch (RuntimeException re) {
        log.error("get failed", re);
        throw re;
    } finally {
        closeTransaction();
    }
}

public List findByExample(Employe instance) {
    log.debug("finding Employe instance by example");
    try {
        List results = sessionFactory.getCurrentSession()
                .createCriteria("tn.ooredoo.kpi.dao.Employe")
                .add(Example.create(instance)).list();
        log.debug("find by example successful, result size: "
                + results.size());
        return results;
    } catch (RuntimeException re) {
        log.error("find by example failed", re);
        throw re;
    }
}

public List findByProprety(Employe instance) {
    log.debug("finding Employe instance by example");
    try {
        openTransaction();
        Criterion critere = Expression.eq("loginEmploye",
                instance.getLoginEmploye());
        List results = sessionFactory.getCurrentSession()
                .createCriteria("tn.ooredoo.kpi.model.Employe")
                .add(critere).list();
        log.debug("find by example successful, result size: "
                + results.size());
        return results;
    } catch (RuntimeException re) {
        log.error("find by example failed", re);
        throw re;
    } finally {
        closeTransaction();
    }
}
}