1

较早的帖子中,我的休眠配置文件有一些未知问题。一个人给了我另一个配置文件来使用,它解决了旧的配置错误。之后,我删除了这些注释附近的代码- “!--禁用缓存--”“!-- UTF8到数据库--”“!--实体映射--”现在我收到一个新错误。但它也引入了一个新错误,如下所示。我如何解决它 ?

org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.1.GA
[main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
[main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
[main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
[main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
[main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
[main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
[main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
[main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect
Apr 17, 2013 3:10:39 AM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: com.examscam.model.User
Apr 17, 2013 3:10:39 AM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity com.examscam.model.User on table User
Apr 17, 2013 3:10:39 AM org.hibernate.cfg.AnnotationConfiguration secondPassCompile
INFO: Hibernate Validator not found: ignoring
[main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - Running hbm2ddl schema export
[main] INFO org.hibernate.tool.hbm2ddl.SchemaExport - exporting generated schema to database
[main] INFO org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.hibernate.connection.C3P0ConnectionProvider
[main] INFO org.hibernate.connection.C3P0ConnectionProvider - C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://127.0.0.1:3306/test
[main] INFO org.hibernate.connection.C3P0ConnectionProvider - Connection properties: {useUnicode=true, user=root, password=****, characterEncoding=UTF-8}
[main] INFO org.hibernate.connection.C3P0ConnectionProvider - autocommit mode: false
Exception in thread "main" java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/DataSources
    at org.hibernate.connection.C3P0ConnectionProvider.configure(C3P0ConnectionProvider.java:176)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:79)
    at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:51)
    at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:252)
    at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:211)
    at com.examscam.model.User.persist(User.java:48)
    at com.examscam.model.User.main(User.java:55)
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.DataSources
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 8 more

XML -

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

    <session-factory>
        <property name="dialect">
            org.hibernate.dialect.MySQLDialect
        </property>
        <property name="connection.url">
            correct url
        </property>
        <property name="connection.username">root</property>
        <property name="connection.password">password</property>
        <property name="connection.driver_class">
            com.mysql.jdbc.Driver
        </property>

    </session-factory>

</hibernate-configuration>
4

4 回答 4

2

原因是你的工程库中没有c3p0.jar,点击下载,把压缩包里的c3p0-0.9.x.jar放到你的工程lib目录下。会好的。

于 2013-04-17T10:34:52.560 回答
2

c3p0-0.9.1.1.jar这个 jar 添加到您的类路径中。

看起来com.mchange.v2.c3p0.DataSources这个类在你的类路径中不存在。

于 2013-04-17T10:32:47.513 回答
0

当心 c3p0 的较新版本,我下载了最新版本 (c3p0-0.9.5-pre9) 并且在其他错误中卡住了几个小时,例如:

org.apache.catalina.core.StandardWrapperValve invoke GRAVE: Servlet.service() 
for servlet default threw exception java.lang.ClassNotFoundException: 
java.lang.AutoCloseable at org.apache.catalina.loader.WebappClassLoader.loadClass

或者

java.lang.ClassNotFoundException: com.mchange.v2.c3p0.DataSources

我建议下载: c3p0-0.9.1并将所有 jar 导入您的项目。

于 2014-10-13T13:12:52.400 回答
0

我刚刚做了一个干净的构建,这个问题就消失了。在 Eclipse 堆错误之后发生在我身上。我不得不重新运行eclipse,杀死tomcat进程。

于 2016-05-25T20:35:33.780 回答