您的位置:首页 > 编程语言 > Java开发

hibernate整合spring的配置原理

2016-05-30 22:22 246 查看
自己做一下spring整合hibernate的配置,真的是不做不知道,一做才发现很多问题:

1.首先是spring整合hibernate的session获取问题,在spring中,用getCurrentSession()方法来获取session,在spring配置hibernate属性中要使用

<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>配置,不能用thread属性

2.在属性注入中定义接口,然后注入实现类,出现了类型不一致问题,在aop-config中加上如下 proxy-target-class=“true”,解决了此问题

<aop:config proxy-target-class="true">
<aop:pointcut id="serviceOperation" expression="execution(* com.grogshop.dao.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation"/>

</aop:config>

3.两者整合配置aop,并且配置事务作用哪些方法的理解:

事务配置作用在哪些指定开头的方法上,而aop指定的就是该事务作用的哪些方法,这些方法中以上面方法打头的方法才作用事务。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: