你的session怎么获得的?
要sessionFactory.getCurrentSession();
不要sessionFactory.openSession();
要sessionFactory.getCurrentSession();
不要sessionFactory.openSession();
解决方案 »
- jsp 与servlet 的连接
- 彻底无奈了,STRUTS2类型转换的异常!内详....谢谢各位了!
- liferay4.2 apacheDS 只能导用户不能导组?????
- import 出错给指点
- 大家有做JAVA图形/图像的不~~??
- Cookie的名字是文件名么
- hibernate 一对一关系描述象这样怎么写?
- Jbuilder9.0企业版调用webservice的问题,求助!!
- J2EE 初学者,不知从何学习,一头雾水,所以送 40 分请指点捷径.谢谢恩人.
- Mybaits框架,后台老是报错,不知如何解决,急急急,在线等
- spring中出现乱码问题,急!
- 为什么这个简单的AOP不能再spring2.0.5下运行,在1.2.9下正常
Set orders=customer.getOrders(); //这句是延迟加载我原来没有用OpenSessionInViewFilter,所以会抱错,
我想添上OpenSessionInViewFilter实现延迟加载,不知道要在web.xml里面怎么写.
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list> <jsp-config>
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>要加上哪些内容才能不报这个错误:
could not initialize proxy - the owning Session was closed
我查到资料要用到OpenSessionInViewFilter,但是不知道怎么写
你通过session.load/get取出了customer对象了,然后由于页面请求完成了
你手工或者通过filter调用了session.close()然后在下一次请求或者调用了session.close之后,你再调用customer.getOrders这样由于customer所关联的session被关闭了,它无法得到orders了你可以在准备getOrders之前重新加载一次order,就是order = session.get(Order.class, order.getId());不过我也觉得这个是Hibernate本身不太好的地方,非常郁闷
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
</plug-in>-->
但是我没有实验成功,有谁能提供一个HibernateInterceptor实现延迟加载的例子吗?