当前位置: 动力学知识库 > 问答 > 编程问答 >

java.lang.ClassNotFoundException: org.hibernate.HibernateException for hibernate 4

问题描述:

I'm trying to set up a web application with tomcat 7.0, java6 and hibernate 4.

Basically, you can say I have the same problem as in this thread: java.lang.ClassNotFoundException: org.hibernate.HibernateException , but I'm not able to solve it. I have checked build path, and everything else I've been able to think of.

So, when trying to have the servlet use the hibernate objects, I get this error:

HTTP Status 500 - Error instantiating servlet class controller.ControlServlet

Stack trace:

java.lang.ClassNotFoundException: org.hibernate.HibernateException

org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)

org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)

controller.SearchCommand.<init>(SearchCommand.java:25)

controller.ControlServlet.<init>(ControlServlet.java:31)

sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

java.lang.reflect.Constructor.newInstance(Unknown Source)

java.lang.Class.newInstance0(Unknown Source)

java.lang.Class.newInstance(Unknown Source)

org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)

org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)

org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)

org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)

org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)

org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)

java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)

java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

java.lang.Thread.run(Unknown Source)

SearchCommand:

public class SearchCommand implements Command{

private BookingDAO dao;

public SearchCommand(){

this.dao = new BookingDAO(); // line 25

}

ControlServlet:

 public ControlServlet() {

super();

commands.put("search", new SearchCommand());

}

BookingDAO:

public class BookingDAO {

private SessionFactory factory;

public BookingDAO(){

try {

factory = new Configuration().configure().buildSessionFactory();

} catch (Throwable ex) {

System.err.println("Failed to create sessionFactory object." + ex);

throw new ExceptionInInitializerError(ex);

}

}

public void getHotel(Booking booking, int hotelId){

Session session = factory.openSession();

Transaction tx = null;

try {

tx = session.beginTransaction();

Hotel hotel = (Hotel) session.get(Hotel.class, hotelId);

booking.setHotel(hotel);

tx.commit();

} catch (HibernateException e) {

if (tx != null)

tx.rollback();

e.printStackTrace();

} finally {

session.close();

}

}

Classpath:

http://i.stack.imgur.com/e1S2a.jpg

Can anyone help me?

分享给朋友:
您可能感兴趣的文章:
随机阅读: