当统计子分类个数时,entity对象已经处于session之外的游离状态,Hibernate的transaction默认lazy=”true”,所以,程序在取数据时会出现错误
解决:
在web.xml文件中设置Filter
解决:
在web.xml文件中设置Filter
- <!-- To Solve an org.hibernate.LazyInitalizationException -->
- <filter>
- <filter-name>Spring penEntityManagerInViewFilter</filter-name>
- <!-- Include this if you are using Hibernate -->
- <!-- org.springframework.orm.hibernate3.support.OpenSessionInViewFilter 用于hibernate+spring -->
- <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>SpringOpenEntityManagerInViewFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>