我用的是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>大家帮我看看是怎么回事?兄弟我谢谢了
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>大家帮我看看是怎么回事?兄弟我谢谢了
解决方案 »
- 该用啥设计模式?
- 关于Tomcat配置的问题
- 用Tomcat作为应用服务器的WEB应用程序的远程维护问题,请大家指教。
- jsp里面table有行数据怎么上传给action 求高手指点!!!
- 关于框架学习的问题,进来有分,大家指点下哦
- 在resin,tomcat中配置了数据源,如何在它们之外利用数据源呢?
- Servlet应用程序必须放在Tomcat的webapps根目录下才能运行吗?
- srping 引用其他property时报空指针。
- 关于用request.getAttribute()的不解问题--救命啊!!
- JBuildX的这个错怎么处理?急~~~
- 想找一个功能相对简单的项目,是一个工程,直接进去就可以了~~~
- SVN
只用过 最基本的