首页新闻找找看学习计划

Hibernate5.2.12连接数据库问题

0
悬赏园豆:20 [已关闭问题] 关闭于 2018-03-12 14:16

刚学Hibernate框架,代码照书上敲的,书上用的Hibernate5.2.7

依赖库已添加:

mysql驱动jar包放在了WebContent/WEB-INF/lib下

进行数据库相关操作时出现ClassNotFound异常

java.lang.ClassNotFoundException: org.hibernate.Query

错误信息为:

严重: Servlet.service() for servlet [StudentServlet] in context with path [/UseHibernate] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.hibernate.Query
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
    at lizhiqiang.servlet.StudentServlet.insertStudent(StudentServlet.java:71)
    at lizhiqiang.servlet.StudentServlet.doPost(StudentServlet.java:50)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)

hibernate.cfg.xml文件内容如下:

复制代码
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE hibernate-configuration PUBLIC
 3     "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 4     "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 5 <hibernate-configuration>
 6     <session-factory>
 7         <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
 8         <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/School</property>
 9         <property name="hibernate.connection.username">root</property>
10         <property name="hibernate.connection.password">root</property>
11         <property name="hibernate.connection.pool.size">20</property>
12         <property name="jdbc.fetch_size">50</property>
13         <property name="Connection.useUnicode">true</property>
14         <property name="connection.characterEncoding">gbk</property>
15         <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
16         <mapping resource="domain.hbm.xml"/>
17     </session-factory>
18 </hibernate-configuration>
复制代码

求解!

╄冷丶夜♂的主页 ╄冷丶夜♂ | 初学一级 | 园豆:68
提问于:2018-01-23 10:22
< >
分享
所有回答(2)
0
dudu | 园豆:41258 (高人七级) | 2018-01-23 11:19
0

怎么感觉你的jar包有点少;

DanBrown | 园豆:1496 (小虾三级) | 2018-01-24 08:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册