This seems like a Spring deal to me, but it only happens when I try to migrate to Hibernate 3, so I thought I would post it here. As you can see, I made all my references lazy="false".
This is actually my second stab at it. The first time I tried uses the OpenSessionInViewInterceptor, like I was with Hibernate2, along with this function whenever I needed the principal from Acegi:
Code:
public WebUser getWebUser() {
SecureContext sc = (SecureContext) (ContextHolder.getContext());
WebUser ret = (WebUser) sc.getAuthentication().getPrincipal();
// We have to get the user from this session again since ACEGI runs
// before our OpenSessionInViewInterceptor is run.
return getWebUser(ret.getWebUserID());
}
but that broke EVERY page, so I moved to the filter and stopped using that function (which makes a lot more sense anyway), but now pages break seemingly randomly. Has anyone seen anything like this before? Thanks!
Web.xmlCode:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/eha-servlet.xml
</param-value>
</context-param>
<filter>
<filter-name>Open Session in View</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Open Session in View</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>Acegi Filter Chain Proxy</filter-name>
<filter-class>net.sf.acegisecurity.util.FilterToBeanProxy</filter-class>
<init-param>
<param-name>targetClass</param-name>
<param-value>net.sf.acegisecurity.util.FilterChainProxy</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Acegi Filter Chain Proxy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>eha</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>eha</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
Hibernate version:3.0rc1
Mapping documents:Code:
<class name="eha.dao.WebUser" table="dbo.webUser">
<cache usage="read-write" />
<id name="webUserID" type="integer">
<generator class="identity"/>
</id>
<many-to-one name="ezHp" column="hpcode" fetch="join" lazy="false"/>
<many-to-one name="ezMemb" column="membID" fetch="join" lazy="false"/>
<property name="username"/>
<property name="password"/>
<many-to-one name="webRole" column="webRoleID" fetch="join" lazy="false"/>
<property name="timestamp" column="`timestamp`" type="timestamp"/>
</class>
<class name="eha.dao.WebRole" table="dbo.webRole">
<cache usage="read-only" />
<id name="webRoleID" type="integer">
<generator class="identity"/>
</id>
<property name="text"/>
<property name="description"/>
<property name="system" type="boolean"/>
<property name="rank" type="integer"/>
</class>
Full stack trace of any exception that occurs:Code:
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80)
org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:133)
eha.dao.WebRole$$EnhancerByCGLIB$$2294de9e.toString(<generated>)
org.apache.taglibs.standard.tag.common.core.OutSupport.out(Unknown Source)
org.apache.taglibs.standard.tag.common.core.OutSupport.doStartTag(Unknown Source)
org.apache.jsp.WEB_002dINF.jsp.webUsers_jsp._jspx_meth_c_out_0(org.apache.jsp.WEB_002dINF.jsp.webUsers_jsp:476)
org.apache.jsp.WEB_002dINF.jsp.webUsers_jsp._jspx_meth_c_forEach_0(org.apache.jsp.WEB_002dINF.jsp.webUsers_jsp:266)
org.apache.jsp.WEB_002dINF.jsp.webUsers_jsp._jspService(org.apache.jsp.WEB_002dINF.jsp.webUsers_jsp:112)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:97)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:917)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:696)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:623)
org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:384)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:344)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:300)
net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:84)
net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter.doFilter(SecurityEnforcementFilter.java:181)
net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
net.sf.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:114)
net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
net.sf.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:372)
net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:217)
net.sf.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
net.sf.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:179)
net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:125)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:172)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
Name and version of the database you are using:
SQLServer 2000