最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SSH整合中 hibernate托管給Spring得到SessionFactory

 更新時間:2009年06月18日 21:43:52   作者:  
Spring文件中的 SessionFactory中 加入為了能得到同一個Session
<prop key="hibernate.current_session_context_class">thread</prop>
然后
Resource resource=new ClassPathResource("/WEB-INF/applicationContext.xml");
BeanFactory factory=new XmlBeanFactory(resource);
SessionFactory sessionFactory = (SessionFactory)factory.getBean("sessionFactory");
就可以得到了
剩下的 不會就回爐吧,我 的 做法是 修改HibernateUtil文件的得到SessionFactory 的方法就 什么都解決了
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
//在hibernate托管給Spring時得到sessionFactory
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
Resource resource=new ClassPathResource("/WEB-INF/applicationContext.xml");
BeanFactory factory=new XmlBeanFactory(resource);
sessionFactory = (SessionFactory)factory.getBean("sessionFactory");
} catch (HibernateException ex) {
throw new RuntimeException("Exception building SessionFactory: "
+ ex.getMessage(), ex);
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
}
//
當(dāng)hibernate沒有托管給Spring使用這種和傳統(tǒng)方式都可以得到啊
sessionFactory = new Configuration().configure("/WEB-INF/hibernate.cfg.xml")
.buildSessionFactory();

相關(guān)文章

最新評論

衡阳市| 桃园县| 商都县| 纳雍县| 图们市| 格尔木市| 吉水县| 射洪县| 桐梓县| 安塞县| 隆德县| 启东市| 清流县| 炉霍县| 东至县| 罗定市| 惠安县| 五大连池市| 乃东县| 宜宾县| 五峰| 井冈山市| 广汉市| 麻江县| 甘南县| 孟州市| 邵阳市| 海林市| 乐东| 新闻| 腾冲县| 灵川县| 九龙坡区| 兴海县| 漳平市| 武隆县| 电白县| 渝北区| 娱乐| 连州市| 吉林省|