Spring+Hibernate声明式事务
来源:互联网 发布:linux确认删除文件指令 编辑:程序博客网 时间:2024/05/20 18:53
配置声明是式事务首先把hibernate.cfg.xml加载进来配置SessionFactory,在Spring中如下配置:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!--property中的name值固定为configLocation
-->
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
接着配置事务管理器:
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<!--
property中的name属性固定为session,ref中的bean为上面的bean中的id值
-->
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
然后配置事务的传播特性如下:
<!--transaction-manager中的值为上面的事务管理器的id值,在这里tx:advice可以理解为AOP中的advice,相当于方法的拦截,这里只是加上声明式事务
-->
<tx:advice id="txadvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
这里配置AOP:
<!--pointcut中的expression中的表达式为具体的方法
advice-ref中指向刚才的tx:advice
pointcut-ref指向的事这里定义的pointcut
-->
<aop:config>
<aop:pointcut id= "addallmethod" expression="execution(* com.sun.manager.*.*(..))"/>
<aop:advisor pointcut-ref="addallmethod" advice-ref="txadvice"/>
</aop:config>
到此整个声明式事务配置完毕!
- Spring+Hibernate声明式事务
- Spring+Hibernate 声明式事务
- Spring+Hibernate : 声明式事务
- Spring+Hibernate声明事务
- Spring结合Hibernate声明式事务配置
- Spring和Hibernate集成--声明式事务
- Spring Hibernate 配置声明式事务无效
- spring+hibernate,采用声明式事务
- Hibernate+Spring中的声明式事务
- spring hibernate 声明式事务配置笔记
- Spring hibernate 声明式事务配置
- Spring与Hibernate集成声明式事务
- 【spring 7】spring和Hibernate的整合:声明式事务
- spring声明式事务
- Spring---声明式事务
- Spring声明式事务
- Spring声明式事务
- spring 声明式事务
- C#中常用的文件操作方法
- Spring 中的声明式事务管理——OpenSessionInViewFilter
- C89和C99标准比较
- python 实现生成目录树及显示文件大小
- Style of WebService: REST vs. SOAP
- Spring+Hibernate声明式事务
- 我的文章一般都很短
- uClinux文件系统及桌面linux的分区
- SQL 游标原理和使用方法
- 自学Java有感
- 面试题:假设你掉了东西又没办法回去捡,你希望掉的不是底下哪一项?
- Use ALSA lib apis to set the Mic Capture Volume
- apple ——we are - are we
- WINCE驱动总结