J2ee项目运行时Session session=HibernateUtil.getSession();出错,求问如何解决
设置断点,发现运行到Sessionsession=HibernateUtil.getSession();该句就停了,单步进入发现会跳到InvocationTargetEx...
设置断点,发现运行到Session session=HibernateUtil.getSession();该句就停了,单步进入发现会跳到InvocationTargetException.java
HibernateUtil中的代码如下:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
public HibernateUtil(){
}
static {
try {
// Create the SessionFactory from standard (hibernate.cfg.xml)
// config file.
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
private static final ThreadLocal localThread = new ThreadLocal();
public static Session getSession() {
Session s = (Session)localThread.get();
if(s == null){
s = sessionFactory.openSession();
localThread.set(s);
}
return s;
}
public static void closeSession(){
Session s = (Session)localThread.get();
if(s != null){
s.close();
localThread.set(null);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
} 展开
HibernateUtil中的代码如下:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
public HibernateUtil(){
}
static {
try {
// Create the SessionFactory from standard (hibernate.cfg.xml)
// config file.
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
private static final ThreadLocal localThread = new ThreadLocal();
public static Session getSession() {
Session s = (Session)localThread.get();
if(s == null){
s = sessionFactory.openSession();
localThread.set(s);
}
return s;
}
public static void closeSession(){
Session s = (Session)localThread.get();
if(s != null){
s.close();
localThread.set(null);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
} 展开
4个回答
展开全部
你先测试有没有进入getSession这个方法呗,一个一个的测
追问
没有进到getSession这个方法,跳到InvocationTargetException.java就出不来了TAT
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
配置有问题吧
追问
可能是哪里出了问题呢?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
得把错误信息贴出来 大家才知道什么错误啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询