一、手动加载 如:
- Hibernate.initialize(obj.getUser());//加载用户对象
二、使用OpenSessionInViewFilter 配置解决延迟加载 如:
- <!--OpenSessionInViewFilter 解决延迟加载问题 -->
- <filter>
- <filter-name>OpenSessionInViewFilter</filter-name>
- <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class>
- <!-- singleSession默认为true,若设为false则等于没用OpenSessionInView -->
- <init-param>
- <param-name>singleSession</param-name>
- <param-value>true</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>OpenSessionInViewFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
本文出自: http://xp9802.iteye.com/blog/1214259 ,转载时请务必保留此出处