关于spring3.2.4与hibernate4.1.2 集成的一些注意事项以及配置

1. 当我们要用sessionFactory.getCurrentSession()的时候一般在配置文件中都需要配置

<prop key="hibernate.current_session_context_class">thread</prop> 

hibernate4 之后由于对事务的支持已经非常好了,而且事务是绑定在session上的。所以网上有好多帖子说

<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop> 配置文件修改成这样。

亲测 其实,这个配置完全不需要写。

2. 配置sessionFactory的时候hibernate4修改为<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 就不要用hibernate3的内容了

3.如果你的框架是springmvc、spring、hibernate这个架构的话  sessionFactory.getCurrentSession(); 出现错误,NO SESSION的情况,请检查springmvc的配置文件中的扫描

 <!-- 使Spring支持自动检测组件,如注解的Controller  这里只能扫描controller包如果扫描了service包 则事务会失效   -->
    <context:component-scan base-package="china.home.daughter.*.*.controller*"/> 这里只能扫描controller包否则会出现事务失效,NO SESSION的情况。

4.spring mvc spring hibernate 配置文件

1.

<?xml version="1.0" encoding="UTF-8"?><!-- xml声明 -->
<!-- xml Schema 命名空间 -->
<!-- 
	xmlns="http://www.springframework.org/schema/beans  声明xml文件默认的命名空间,表示未使用其他命名空间的所有标签的默认命名空间
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance 声明XML Schema 实例,声明后就可以使用 schemaLocation 属性了
	xmlns:aop="http://www.springframework.org/schema/aop 声明前缀为aop的命名空间,后面的URL用于标示命名空间的地址不会被解析器用于查找信息。
	其惟一的作用是赋予命名空间一个惟一的名称。当命名空间被定义在元素的开始标签中时,所有带有相同前缀的子元素都会与同一个命名空间相关联
	xmlns:context="http://www.springframework.org/schema/context 声明前缀为context的命名空间
	xmlns:tx="http://www.springframework.org/schema/tx 声明前缀为t
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值