package persistence;
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("Exception building SessionFactory;"
+ ex.getMessage(), ex);
}
}
public static Session currentSession() throws HibernateException
...{
Session s = sessionFactory.openSession();
return s;
}
public static void closeSession(Session s)
...{
if (s != null)
s.close();
}
}
一个简单的Hibernate例子
最新推荐文章于 2026-01-06 12:00:34 发布
本文介绍了一个用于管理Hibernate会话的实用工具类的设计方案。该工具类提供了获取当前活动会话及关闭会话的方法,有助于简化应用程序中数据库操作的代码。
1129

被折叠的 条评论
为什么被折叠?



