日期:2014-05-20  浏览次数:20792 次

hibernate小问题
搭建Hibernate环境时用的一个小程序,老是调试不能通过,请多多指教,不胜感激!
test.java
package lee;

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


public class Test
{
  public static void main(String[] args) throws Exception
  {
  Configuration conf = new Configuration().configure();
  SessionFactory sf = conf.buildSessionFactory();
  Session sess = sf.openSession();
  System.out.println(sess);
  Transaction tx = sess.beginTransaction();
  News n = new News();
  n.setTitle("test");
  n.setContent("hello");
  sess.save(n);
  tx.commit();
  sess.close();  
  }
}
错误提示:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
at lee.Test.main(Test.java:13)





------解决方案--------------------
jar包不全吧,另外hibernate配置文件在哪里加载
------解决方案--------------------
项目的classpath有错
重新建一个项目然后把这些代码拷过去就可以了。