自己创建sessionFactory与用spring中提供的sessionFactory的不同
来源:互联网 发布:云购开奖计算公式 编辑:程序博客网 时间:2024/04/26 13:13
自己写的HibernateUtil
public class HibernateUtil {
private static SessionFactory factory=null;
static{
try {
Configuration cfg=new Configuration().configure();
factory=cfg.buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
}
}
public Session getSession(){
// return factory.openSession();
return factory.getCurrentSession();
}
}
用spring的
<bean id="categoryImpl" class="impl.CategoryImpl">
<property name="sessionFactory" ref="sessionFactory"/> // 这里如果用自己写的sessionfactory就不用引入,如果用spring自带的就必须引入
</bean>
<bean id="categoryService" class="service.CategoryService" autowire="byName"/>
<bean id="CategoryAction" class="action.CategoryAction" autowire="byName" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!-- <property name="dataSource" ref="dataSource"></property> -->
</bean>
用到sessionfactory的地方
public class CategoryImpl extends HibernateDaoSupport implements ICategory {
@Override
public List<Category> getAll() {
return this.getHibernateTemplate().find("from Category");//用自带的sessionfactory 下边的事自己写的
// hql = "from Category";
// session = util.getSession();
// query = session.createQuery(hql);
// return query.list();
}
- 自己创建sessionFactory与用spring中提供的sessionFactory的不同
- Hibernate 中 SessionFactory的创建
- hibernate中SessionFactory的创建
- hibernate创建sessionFactory的不同方式
- 创建SessionFactory的方式
- SessionFactory的创建方式
- hibernate5.x 版本中创建SessionFactory的思路与方法
- hibernate4.0中SessionFactory的创建
- hibernate4.0中SessionFactory的创建
- hibernate4.3中SessionFactory的创建
- Spring中注入Hibernate的SessionFactory
- 关于spring中加入两个不同数据库的sessionfactory遇到的问题.
- 自学java SessionFactory的创建
- hibernate 创建 SessionFactory 的变化
- Hibernate SessionFactory 的创建方式
- Spring的sessionFactory配置详解
- Spring创建Hibernate的SessionFactory的简易方法
- Hibernate 中 的 SessionFactory 接口
- NVD3.js 中 图例 (legend) 中文字符 被图标遮住
- 智利地震威海地震尼玛又地震 地球最近很闹腾!
- 用科学方法研究工作生活平衡
- SharePoint Ribbon菜单ID总结
- C++编译器越界检查机制
- 自己创建sessionFactory与用spring中提供的sessionFactory的不同
- Android中通过pid获取app包名
- inputStream 、outputStream、String相互转化
- 在公司问上级问题的艺术
- 冯绍峰等提供
- 基线(Baseline)的含义以及在Android中的使用
- struts2 基础的环境搭建
- jsp 页面传值 到后台 中文乱码解决方法
- 事务基本特性和两阶段提交协议