java.lang.ClassNotFoundException:org.hibernate.criterion.Projection

时间:2013-02-25 12:25:42

标签: eclipse hibernate servlets

早上好,请我不知道如何解决这个异常,我在eclipse下使用ApcheTomcat 7,每次运行我的servlet时抛出异常,这里是我的servlet更清晰:

package servlets;

import java.util.*;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 import dao.*;

@WebServlet("/AdminServlt")
public class AdminServlt extends HttpServlet {
private static final long serialVersionUID = 1L;
CarHome carDao;

public void init(ServletConfig config) throws ServletException{
    carDao = new CarHome();
    }

protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    populateAdminView(request, response);
}

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
}

  public void populateAdminView(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
    ArrayList productsList = (ArrayList) carDao.extractAdminAttributes();
    HttpSession session = request.getSession(true);
    session.setAttribute("product_list",productsList);
    RequestDispatcher rd = request.getRequestDispatcher("Admin.jsp");
    rd.forward(request, response);
}

}

这里是CarHome.java

package dao;
import java.util.ArrayList;
import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;  
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.*;
import entity.*;

    public class CarHome {

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

private final SessionFactory sessionFactory = getSessionFactory();


public List extractAdminAttributes() {
    log.debug("Extracting car attributes for administrator view");
    try {
        ArrayList results = (ArrayList) sessionFactory
                .getCurrentSession()
                .createCriteria("pojo.Car")
                .setProjection(
                        Projections.projectionList()
                                .add(Projections.property("carDesc"))
                                .add(Projections.property("price"))
                                .add(Projections.property("quantity")));

        return results;
    } catch (RuntimeException re) {
        log.error("find by admin view failed");
        throw re;
    }
  }
  }

这是异常的堆栈跟踪

java.lang.ClassNotFoundException: org.hibernate.criterion.Projection
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
servlets.AdminServlt.init(AdminServlt.java:31)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

2 个答案:

答案 0 :(得分:2)

我已经解决了我的问题很简单,主要原因是hibernate.cor.jar文件不在应用程序的web内容下的lib文件夹中,当我把它放在那里它工作正常

答案 1 :(得分:0)

我遇到了同样的问题,但在我的情况下,我使用eclipse重新命令顶部的hibernate-cor.jar

选择了项目 - >右键单击 - >构建路径 - >订单标签 - >选择hibernate-cor.jar点击顶部