Hibernate入门例子-高分求解
package dev.hibernate;
import java.io.Serializable;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.*;
import net.sf.hibernate.Session;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class HibernateUtil{
public static void main(String[] args) {
try{
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
User p = new User();
p.setUid(new Integer(1));
p.setUsername( "LDQ ");
p.setPassword( "12345 ");
session.save(p);
tx.commit();
session.close();
}catch(Exception ex){
throw new
ExceptionInInitializerError(ex);
}
}
}
编译没有问题,只要运行到【new Configuration()】就发生错误啦~
搞了2天了就是不明白怎么才能在Eclipse中运行这个程序
---------------------------------
Exception in thread "main "
java.lang.ExceptionInInitializerError at dev.hibernate.HibernateUtil.main(HibernateUtil.java:20)
Caused by:
org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.Log
ConfigurationException:
java.lang.NullPointerException (Caused by java.lang.
NullPointerException) (Caused by org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException))
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
at net.sf.hibernate.cfg.Configuration. <clinit> (Configuration.java:95)
... 1 more
Caused by: org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException)
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:397)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
... 5 more
Caused by: java.lang.NullPointerException
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:374)
... 6 more
-