Hibernate代码不工作,如何解决? [英] Hibernate code is not working, how to fix?

查看:114
本文介绍了Hibernate代码不工作,如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早期文章中,我的hibernate配置文件有一些未知问题。一个人给了我另一个配置文件来使用,并解决了旧的配置错误。之后,我删除了这些注释附近的代码 - - disable cache - ! - UTF8 to database - ! - Entity Mappings - 现在我得到一个新的错误。 / strong>但它也引入了一个新的错误,下面给出。如何修复它?

In an earlier post , my hibernate config file had some unknown problem. One person gave me another config file to use and that resolved the old config error. After that I removed the code near these comments - "!-- disable cache --" "!-- UTF8 to database --" "!-- Entity Mappings --" and now i get a new error. But it also introduced a new error which is given below. How do I fix it ?

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>


推荐答案

原因在于没有c3p0.jar您的项目库,点击下载并将zip文件中的c3p0-0.9.x.jar放入您的项目lib目录中。它会好的。

The reason is that there is no c3p0.jar in your project library, click to download and put the c3p0-0.9.x.jar in the zip file into your project lib directory. It'll be OK.

这篇关于Hibernate代码不工作,如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆