0
votes

hy everyone i need your help to fix my problem i don't know why it doesn't work: An Error Occurred:

java.lang.NoClassDefFoundError: Could not initialize class tn.ooredoo.kpi.util.HibernateUtil - Stack Trace

javax.faces.el.EvaluationException: java.lang.NoClassDefFoundError: Could not initialize class tn.ooredoo.kpi.util.HibernateUtil at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:98) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98) at javax.faces.component.UICommand.broadcast(UICommand.java:311) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) Caused by: java.lang.NoClassDefFoundError: Could not initialize class 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 tn.ooredoo.kpi.controller.LoginCtr.connecter(LoginCtr.java:37) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.el.parser.AstValue.invoke(AstValue.java:278) at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:84) ... 24 more

2
What are you trying to do actually? - niyasc
show the code of EmployeDao - Nimesh
my problem is this error and i just put now the code of employeDao - Slim Chaffar

2 Answers

0
votes

"tn.ooredoo.kpi.util.HibernateUtil" - This class was unable to be found..

This is the result of a reference from an unknown class (You did not include the full error, so it is impossible to say EXACTLY what is going on)

All I can say for sure is that your class has an indirect reference to tn.ooredoo.kpi.util.HibernateUtil and the class could not be found - it also appears that the class that could not be located is a portion of a library that may have been excluded during build or run (most likely run.)

0
votes
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();
    }
}
}