您的位置:首页 > 其它

学习hibernate时遇到的问题

2010-03-29 17:14 295 查看
在学习hibernate时,我建立了一个hibernate库,在什么都配置正确的情况下,出现了如下问题:

Exception in thread "main" java.lang.ExceptionInInitializerError

at Test.main(Test.java:21)

Caused by: java.lang.NullPointerException

at org.slf4j.LoggerFactory.singleImplementationSanityCheck(LoggerFactory.java:192)

at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:113)

at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)

at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)

at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)

... 1 more

很不解!网上搜了一下,说是eclipse出的问题,呵呵,还是不解

配置文件如下:

hibernate.cfg.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">

<!-- hibernate-configuration是连接配置文件的根元素 -->

<hibernate-configuration>

<session-factory>

<!-- 指定连接数据库所用的驱动 -->

<property name="connection.driver_class">

com.mysql.jdbc.Driver

</property>

<!-- 指定连接数据库的url和Hibernate链接的数据库名 -->

<property name="connection.url">

jdbc:mysql://localhost/test

</property>

<!-- 指定连接数据库的用户名 -->

<property name="connection.username">root</property>

<!-- 指定连接数据库的密码 -->

<property name="connection.password">test</property>

<!-- 指定连接池的大小 -->

<!-- C3P0 connection pool -->

<property name="hibernate.c3p0.max_size">20</property>

<property name="hibernate.c3p0.min_size">1</property>

<property name="hibernate.c3p0.timeout">5000</property>

<property name="hibernate.c3p0.max_statements">100</property>

<property name="hibernate.c3p0.idle_test_period">3000</property>

<property name="hibernate.c3p0.acquire_increment">2</property>

<property name="hibernate.c3p0.validate">true</property>

<property name="hbm2ddl.auto">create</property>

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

<mapping resource="hibernate/News.hbm.xml" />

</session-factory>

</hibernate-configuration>

News.cfg.xml配置文件

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!--

映射文件的根元素

-->

<hibernate-mapping package="hibernate">

<!-- 每个class对应一个对象 -->

<class name="News" table="news_table">

<id name="id" >

<generator class="identity"></generator>

</id>

<property name="title"></property>

<property name="content"></property>

</class>

</hibernate-mapping>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: