求助:我在ubuntu9.04使用eclipse编写程序出现了难以理解的错误!求助大家了

sh/bash/dash/ksh/zsh等Shell脚本
回复
云端小飞象
帖子: 3
注册时间: 2009-11-07 16:50

求助:我在ubuntu9.04使用eclipse编写程序出现了难以理解的错误!求助大家了

#1

帖子 云端小飞象 » 2009-11-13 11:07

我在eclipse中使用hibernate3.3,编写一个十分简单的数据库初始化的程序,下面是我的代码,请大家看看:
Event.java
package com.hmy.hibernate;

import java.util.Date;

public class Event {
private Long id;
private String title;
private Date date;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public Event() {
super();
// TODO Auto-generated constructor stub
}
}
HibernateUtil.java
package com.hmy.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
private static SessionFactory factory;

static {
try {
Configuration cfg = new Configuration().configure();
factory = cfg.buildSessionFactory();
}catch(Exception e) {
e.printStackTrace();
}
}

public static SessionFactory getSessionFactory() {
return factory;
}

public static Session getSession() {
return factory.openSession();
}

public static void closeSession(Session session) {
if (session != null) {
if (session.isOpen()) {
session.close();
}
}
}

}
ExportDB.java //用于初始化,望数据库件表!错误就出现在这里。
package com.hmy.hibernate;

import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class ExportDB {

/**
* @param args
*/
public static void main(String[] args) {
Configuration cfg = new Configuration().configure();

SchemaExport export = new SchemaExport(cfg);

export.create(true, true);

}
}
Event.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd">
<hibernate-mapping>

<class name="events.Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="native"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</class>
</hibernate-mapping>
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/hibern ... on-3.0.dtd">

<hibernate-configuration>

<session-factory>

<!-- Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@192.168.0.221:1521:hmy</property>
<property name="connection.username">hmy</property>
<property name="connection.password">123</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.OracleDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

<mapping resource="com/hmy/hibernate/Event.hbm.xml"/>

</session-factory>

</hibernate-configuration>

系统环境,ubuntu9.04, jdk1.6,
可以正常的java程序的编写,比如helloworld.java,可以正常显示。

出现的错误:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.hmy.hibernate.ExportDB.main(ExportDB.java:12)
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

不知道问题出现在哪里?请大家帮我看看,是不是ubuntu的权限问题。我没有在root下,在一般的帐户下!
回复