当前位置: 代码迷 >> Java Web开发 >> Hibernate入门事例-高分求解
  详细解决方案

Hibernate入门事例-高分求解

热度:66   发布时间:2016-04-17 15:44:33.0
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.LogConfigurationException:   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


------解决方案--------------------
你的配置文件呢

------解决方案--------------------
需要入门例子,请留下邮件地址或发
yzh963@vip.sina.com跟我要,免费提供

------解决方案--------------------
要把你的hibernate.cfg.xml放在src目录下,还有可能你少导了一些jar包!
------解决方案--------------------
<id name= "uid " type= "integer ">
<column name= "uid " />
<generator class= "native " />
  相关解决方案