-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Migration pains: lazy load errors.
PostPosted: Thu Mar 24, 2005 8:23 pm 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
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.xml
Code:
<?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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 25, 2005 4:48 am 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
I am not 100% sure if this is new with hibernate3, but for what I know even properties are "lazy" by default.
Lazy is the default now: http://www.hibernate.org/250.html

Now, if your webRole is loaded and you havent accessed any property but closed the session the exception you shown happens. I dont know your toString so maybe your problem might be with your collections, but this makes no difference I think.

You can get a detached pojo into the current session using e.g.
session.update(pojo) or session.lock(pojo, ....) depending your needs.
Read: http://www.hibernate.org/168.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 25, 2005 12:03 pm 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
imario wrote:
I am not 100% sure if this is new with hibernate3, but for what I know even properties are "lazy" by default.
Lazy is the default now: http://www.hibernate.org/250.html

Now, if your webRole is loaded and you havent accessed any property but closed the session the exception you shown happens. I dont know your toString so maybe your problem might be with your collections, but this makes no difference I think.

You can get a detached pojo into the current session using e.g.
session.update(pojo) or session.lock(pojo, ....) depending your needs.
Read: http://www.hibernate.org/168.html


That's why this is so weird though, because the entire request is wrapped in an OpenSessionInViewFilter, so no sessions should be closed until the end of the request. And I never store anything in the servlet session, so every object is new from Hibernate for every request.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.