我初学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包都倒进去了啊
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包都倒进去了啊
解决方案 »
- ssh工程整合了 cxf 启动成功,但是访问失败
- 技术求教:关于java服务器与android应用对接技术
- 怎么用java置前显示一个打开的文件?
- 烦人的浏览器后退按钮!!!
- 关于 JSTL 标准标签库的一点疑问
- 谁知道那里有基与struts的oa办公系统源代码么
- 北京大学 LIFERAY.中国 首届全球注册高级讲师认证暨LIFERAY推介发布会
- 如何写这样struts的标签和javascripe语句
- 大家讨论一下,sessionbean和entitybean在项目当中的实际应用!
- 大家救命,关于COM+和EJB,大家快点帮忙,要不我就完蛋了,急死我了,救命阿。
- 关于struts的标签
- 50分 Hibernian NoClassDefFoundError异常
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)
你的xml放在哪了