一、手动加载 如:
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> 


只有注册用户登录后才能发表评论。


网站导航:
 

posts - 34, comments - 38, trackbacks - 0, articles - 0

Copyright © 陈小东