HibernateUtil 工具类错误 ....我能问下你写这个干吗? 这个HibUtil不是Hib自己自带的么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我知道了, 在catch 块里面还要抛一个异常,throw new ExceptionInInitializerError(ex). 可是我就是不明白为什么代码已经包含在 try,catch 里面了,怎么还要抛啊 ! 这是个什么异常 HibernateUtil.java import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; public class HibernateUtil { private static final SessionFactory sessionFactory; static { try { sessionFactory = new Configuration().configure().buildSessionFactory(); } catch(Throwable ex){} } public static final ThreadLocal <Session> tLocalsess = new ThreadLocal <Session>(); public static final ThreadLocal <Transaction> tLocaltx = new ThreadLocal <Transaction>(); public static Session currentSession() { Session session = (Session)tLoclasess.get(); try { if(session==null ¦ ¦ !session.isOpen()) { session = openSession(); tLocalsess.set(session); } } catch(Exception ex){} return session; } public static void closeSession() { Session session = (Session)tLocalsess.get() tLocalsess.set(null); try { if(session!=null && session.isOpen()) { session.close(); } } catch(Exception ex){} } //以下省略开始,提交,回滚事物等方法 ....................... ............................. ............................. public staitic Session openSession() throws HibernateException { return getSessionFactory().openSession(); } public static SessionFactory getSessionFactory() throws HibernateException { return sessionFactory(); } } private static final SessionFactory sessionFactory = null; 就好啦 private static final SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); 使用XmlHttpRequest请求Serlvlet的一个小错误,麻烦各位给看看! struts2表单内的排版问题 jfreechart 折线图多条线以及图例的设置 fckeditor使用的相关问题 项目发布服务器出现大量进程 请问谁知道java开源进锁存软件 关于extjs节点可编辑,求大神 希望Csdn能真正出一,2个高手帮我解决的邮件内容乱码问题 正则表达式如何提取<>对应的每一对标签 request.getSession(false) 引起的疑问 ejb 会话bean 的疑惑 如何将动态的JSP页面转化成静态的HTML页面
可是我就是不明白为什么代码已经包含在 try,catch 里面了,怎么还要抛啊 ! 这是个什么异常
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration; public class HibernateUtil
{
private static final SessionFactory sessionFactory; static
{
try
{
sessionFactory = new Configuration().configure().buildSessionFactory();
}
catch(Throwable ex){}
} public static final ThreadLocal <Session> tLocalsess = new ThreadLocal <Session>();
public static final ThreadLocal <Transaction> tLocaltx = new ThreadLocal <Transaction>(); public static Session currentSession()
{
Session session = (Session)tLoclasess.get(); try
{
if(session==null ¦ ¦ !session.isOpen())
{
session = openSession();
tLocalsess.set(session);
}
}
catch(Exception ex){}
return session;
} public static void closeSession()
{
Session session = (Session)tLocalsess.get()
tLocalsess.set(null); try
{
if(session!=null && session.isOpen())
{
session.close();
}
}
catch(Exception ex){}
} //以下省略开始,提交,回滚事物等方法
.......................
.............................
............................. public staitic Session openSession() throws HibernateException
{
return getSessionFactory().openSession();
} public static SessionFactory getSessionFactory() throws HibernateException
{
return sessionFactory();
}
}