Hi guys,
I'm using Spring and Hibernate in my Web application. When I try to access a hibernate object from my
struts action class or my
JSP page, I get an exception stating:
Uncaught exception thrown in one of the service methods of the
servlet: action. Exception thrown : javax.servlet.ServletException: could not initialize proxy - the owning Session was closed
Does anyone know what I'm doing wrong and how to solve the problem.
Here's my code:
/////WEB.XML//////////////
<!-- =================== Define Spring Bean Definition Files to be loaded ================== -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:com/PBCoreApp/architecture/applicationContext.xml</param-value>
</context-param>
<!--
<context-param>
<param-name>parentContextKey</param-name>
<param-value>pb.model</param-value>
</context-param>
-->
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<!-- =================== Spring Context Loader Servlet ================== -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
////JAVA CODE//////
BusinessServiceCbo businessServiceCbo = new
BusinessCbo businessCbo = new BusinessCbo();
businessCbo = businessDao.findById(businessId);
List serviceList = new ArrayList( businessCbo.getBusinessServices());
businessDetailsDto.setServiceList(serviceList);
//////ACTION CLASSS///
System.out.println("Service List: " + businessDetailDto.getServiceList()); //error occurs here!!!
///APPLiCATION Context.xml /////
<bean id="businessBSTarget" class="com.PBCoreApp.business.impl.BusinessBSImpl">
<property name="businessDao"><ref local="businessDao" /></property>
</bean>
<bean id="businessBS" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>com.PBCoreApp.business.BusinessBS</value>
</property>
<property name="target">
<ref local="businessBSTarget" />
</property>
<property name="interceptorNames">
<list>
<value>hibernateInterceptor</value>
</list>
</property>
</bean>
/////STRUTS-CONFIG//////
<!-- ============================= Spring Plugin ================================== -->
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property
property="contextConfigLocation"
value="/WEB-INF/presentationContext.xml classpath*:com/PBCoreApp/architecture/applicationContext.xml" />
</plug-in>
Pls...HeLP!!!