spring4+springmvc+springdataJPA+hibernate4整合懒加载问题
发布时间:2020-12-13 20:46:45 所属栏目:PHP教程 来源:网络整理
导读:摘要 第1个问题 解决办法 第2个问题 解决办法 摘要 本文主要是为了解决“spring4+springmvc+springdataJPA+hibernate4整合”,注解了OneToMany、ManyToOne,并配置了懒加载,然后报错的问题 第1个问题 org.hibernate.LazyInitializationException: could not
摘要本文主要是为了解决“spring4+springmvc+springdataJPA+hibernate4整合”,注解了OneToMany、ManyToOne,并配置了懒加载,然后报错的问题 第1个问题org.hibernate.LazyInitializationException: could not initialize proxy - no Session at 解决办法:在web.xml中,配置springSevlet的位置,使用org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter,代码以下: <filter>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> 第2个问题org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: .......,no session or session was closed 1般是在定时任务quartzJob中,或Junit测试中使用懒加载出现的毛病 解决办法:添加事务配置注解。junit代码以下: @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"file:src/main/webapp/WEB-INF/applicationContext.xml","file:src/main/webapp/WEB-INF/demo-servlet.xml"})
@Transactional
public class Test { 终了。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |