我用的是jpa,在页面中调用childs的size()方法,数据是空的也不报错,后来在action调用这个方法终于报错了,
failed to lazily initialize a collection of role: com.hanyu.shop.modle.product.ProductType.childtypes, no session or session was closed 
可是我明明加了filter的啊,这是为什么呢?感觉是hibernate和j2ee不兼容
我使用的版本是
struts-2.1.8.1-all.zip
hibernate-distribution-3.5.0-Final
spring-framework-3.0.2.RELEASE
之前在做junit测试的时候就发现,Spring的sessionFactory注入不成功,当去掉j2ee jar包的时候再能测试,至于在tomcat下还能运行,这个我也不知道
看我的配置web.xml
<!-- Hibernate Open Session In View filter-->
 <filter>
<filter-name>osivFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>osivFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>Action-->查询记录集
pager= productTypeService.getScrollData(ProductType.class,
pager.getOffset(),pager.getPagesize() , jpql.toString(), params.toArray(), orderby);
//下面是测试出问题的地方
for (Iterator ite = pager.getPages().iterator(); ite.hasNext();) {
ProductType type = (ProductType) ite.next();
System.out.println(type.getChildtypes());//在得到childs的时候报错no session
}
这个是页面,不过还没到这地方就出错了
<td bgcolor="f5f5f5"> <div align="center"><s:property value="typeid"/></div></td>
      <td bgcolor="f5f5f5"> <div align="center"><a href="<s:url action="productTypeManage_updateInput?typeD.typeid=%{typeid}" namespace="/productType"/>">
  <img src="/images/edit.gif" width="15" height="16" border="0"></a></div></td>
      <td bgcolor="f5f5f5"> <div align="center"><a href='<s:url action="productType_list?typeD.parentid=%{typeid}" namespace="/productType"/>'><s:property value="name"/></a> <s:if test="true"><font color=red>(有<s:property value="childtypes" default="false"/>个子类)</font></s:if></div></td>
  <td bgcolor="f5f5f5"> <div align="center"><a href="<s:url action="productTypeManage_addInput?typeD.parentid=%{typeid}" namespace="/productType"/>">创建子类别</a></div></td>
  <td bgcolor="f5f5f5" align="center"><s:property value="parent.name"/></td>大家帮我看看是怎么回事?兄弟我谢谢了