Spring下Hibernate lazy load的事务解决办法
来源:互联网 发布:cn域名审核 编辑:程序博客网 时间:2024/06/07 00:48
用事务方法解决在Spring下Hibernate的延迟加载,记录一下,免得忘记。
1、applicationContext.xml里
加入以下黑体部分:
...
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
...
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
...
2、对进行lazy bean操作的方法添加Annotation:
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
这样这个方法范围里面对bean的操作就不会报org.hibernate.LazyInitializationException错误了
3、如果此bean要传出这个方法的范围,需要在方法里强制加载lazy属性:
Hibernate.initialize(bean.lazyProperty)
- Spring下Hibernate lazy load的事务解决办法
- Hibernate lazy load.
- Hibernate lazy load
- spring mvc lazy load problem
- 基于Spring+Hibernate+DAO的hibernate的lazy的实现.
- hibernate 延迟加载(Lazy)问题spring下解决方法
- Spring 事务失效的解决办法
- spring hibernate事务的流程
- 用 OpenSessionInViewInterceptor 的思路解决 Spring框架中的Hibernate Lazy
- Spring中解决Hibernate的lazy加载问题
- Spring中解决Hibernate的lazy加载问题
- Spring使用OpenSessionInViewFilter解决Hibernate的lazy延时加载问题
- 用 OpenSessionInViewInterceptor 的思路解决 Spring框架中的Hibernate Lazy
- Spring使用OpenSessionInViewFilter解决Hibernate的lazy延时加载问题
- Spring使用OpenSessionInViewFilter解决Hibernate的lazy延时加载问题
- Spring使用OpenSessionInViewFilter解决Hibernate的lazy延时加载问题
- Spring使用OpenSessionInViewFilter解决Hibernate的lazy延时加载问题
- Spring使用OpenSessionInViewFilter解决Hibernate的lazy延时加载问题
- 解决mysql“Access denied for user 'root'@'localhost'”
- 利用总线进行系统扩展
- 细节决定ERP项目启动会的成败
- U-boot移植问题记录
- Havel-Hakimi定理
- Spring下Hibernate lazy load的事务解决办法
- matlab图形的字体
- 'make menuconfig' requires the ncurses libraries.
- 关于"error LNK2019: unresolved external symbol _SipShowIM referenced in function "protected" 解决方法
- DirectX 11 SDK文档(四)
- Nginx0.8.54+Tomcat6实现负载均衡
- VBS菜鸟实战续篇
- Ubuntu下:make menuconfig Error 2('make menuconfig' requires the ncurses libraries)
- 纯Java开发的游戏引擎V0.4--DEMO2 -- 物理引擎