我初学hibernate框架,在敲第一个示例的就出问题了,org.hibernate.cfg.Configuration初始化不成功,package com;import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();//这里出错
} catch (HibernateException ex) {
throw new RuntimeException("hibernate exception");
}
} private static final ThreadLocal<Session> SESSIONCONTAINER = new ThreadLocal<Session>(); public static Session currentSession() {
Session hibernateSession = (Session) SESSIONCONTAINER.get();
if (null == hibernateSession) {
hibernateSession = sessionFactory.openSession();
SESSIONCONTAINER.set(hibernateSession);
}
return hibernateSession;
} public static void closeSession() {
Session session = SESSIONCONTAINER.get();
if (null == session)
SESSIONCONTAINER.set(null);
else
session.close();
}
}另 我用的是MyEclipse,运行之前没有任何错误提示,运行时出现运行时异常,好像意思是找不到类定义,但是我明明把jar包都倒进去了啊

解决方案 »

  1.   

    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 com.HibernateUtil.<clinit>(HibernateUtil.java:12)
    at com.MyTest.main(MyTest.java:15)
      

  2.   

    已解决,确实是用的那个jar包不全,谢谢楼上两位了
      

  3.   

    configure()默认找src下有没有hibernate.cfg.xml
    你的xml放在哪了