spring+hibernate xml和注解方式配置事务
2014-08-15 00:00
453 查看
一 如果使用注解方式配置事务 , 那么在applicationContext.xml中要配置好
打开注解事务,然后在需要事务的方法上面加上如下注解:
二 如果使用xml方式配置事务, 那么在applicationContext.xml中要如下配置:
在spring + hibernate配置事务的过程中发现一个问题。就是hibernate的sessionFactory必须使用数据源才支持事务,如果直接在hibernate配置文件中连接数据源 ,那么按照上面的方式配置好的事务是没有用的。
<tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" />
打开注解事务,然后在需要事务的方法上面加上如下注解:
@Transactional(propagation=Propagation.REQUIRED , rollbackFor = java.lang.Exception.class)
二 如果使用xml方式配置事务, 那么在applicationContext.xml中要如下配置:
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:advice id="transactionAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="execution(* com.zf.service.*.*(..))" id="servicePoint"/> <aop:advisor advice-ref="transactionAdvice" pointcut-ref="servicePoint" /> </aop:config>
在spring + hibernate配置事务的过程中发现一个问题。就是hibernate的sessionFactory必须使用数据源才支持事务,如果直接在hibernate配置文件中连接数据源 ,那么按照上面的方式配置好的事务是没有用的。
相关文章推荐
- spring+hibernate xml和注解方式配置事务
- spring 基于XML和注解的两种事务配置方式
- Spring整合Hibernate管理事务(xml配置方式)
- Spring 管理hibernate事物,xml配置,注解 两种实现方式
- servlet调用spring容器中的bean,的两种方式一种注解一种xml配置
- spring采用基于xml配置方式进行事务的处理
- spring配置事务之注解方式
- spring aop的使用(注解方式以及基于xml配置方式)
- Spring3与Hibernate4整合,Spring中配置Hibernate基于XML和annotation的sessionFactory方式。
- spring学习笔记10--Spring+jdbc组合开发(注解方式配置事务)
- spring整合hibernate(注解、xml)applicationContext.xml配置
- spring配置事务之xml方式
- 使用注解方式配置spring中的jdbc事务
- spring学习笔记12----Spring+jdbc组合开发( 采用基于xml方式配置事务)
- Spring 3.0.5 MVC 基于注解ehcache.xml 配置方式
- spring采用基于xml配置方式进行事务的处理
- 支持hibernate注解和xml共存的Spring配置
- Spring 采用注解方式配置事务
- hibernate 注解配置<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/X
- Spring2.5.x以后使用注解方式的事务管理配置