-->
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: failed to lazily initialize a collection of role
PostPosted: Fri May 25, 2007 7:39 am 
Newbie

Joined: Sun Sep 19, 2004 9:23 pm
Posts: 7
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1
Name and version of the database you are using:SQL SERVER 2000

I have 3 table,
SYS_USER:
Fields:USER_CODE,USER_NAME
SYS_ORGANIZATION:
Fields:ORG_CODE,ORG_NAME
O_ORG_USER:
Fields:OID,ORG_CODE,USER_CODE

The below code is right
Code:
SysUser sysuser = this.getSysUser(new Long(2000000001));
((OOrgUser)sysuser.getOOrgUsers().iterator().next()).getSysOrganization().getOrgName();


The below code is wrong
Code:
SysOrganization sysorg = this.getSysOrganizationDAO().findById(new Long(1000000000));
((OOrgUser)sysorg.getOOrgUsers().iterator().next()).getSysUser().getOrgName()


SysUser.hbm.xml
Code:
        <set name="OOrgUsers" inverse="true" lazy="true">
            <key>
                <column name="USER_CODE" />
            </key>
            <one-to-many class="cn.net.ecode.bean.OOrgUser" />
        </set>


SysOrganization.hbm.xml
Code:
        <set name="OOrgUsers" inverse="true" lazy="true">
            <key>
                <column name="ORG_CODE" />
            </key>
            <one-to-many class="cn.net.ecode.bean.OOrgUser" />
        </set>


OOrgUser.hbm.xml
Code:
        <many-to-one name="sysOrganization" class="cn.net.ecode.bean.SysOrganization">
            <column name="ORG_CODE" />
        </many-to-one>
        <many-to-one name="sysUser" class="cn.net.ecode.bean.SysUser">
            <column name="USER_CODE" />
        </many-to-one>


Code:
2007-05-25 19:16:41,437 [org.hibernate.LazyInitializationException]-[ERROR] failed to lazily initialize a collection of role: cn.net.ecode.bean.SysOrganization.OOrgUsers, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: cn.net.ecode.bean.SysOrganization.OOrgUsers, no session or session was closed
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
   at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
   at org.hibernate.collection.PersistentSet.toString(PersistentSet.java:309)
   at java.lang.String.valueOf(Unknown Source)
   at java.lang.StringBuilder.append(Unknown Source)
   at cn.net.ecode.business.implement.sys.SysOrgBOImpl.getOrg(SysOrgBOImpl.java:181)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:199)
   at $Proxy1.getOrg(Unknown Source)
   at cn.net.ecode.struts.action.sys.SysOrgAction.execute(SysOrgAction.java:100)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
   at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:264)
   at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:110)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:135)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java:106)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:217)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
   at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:148)
   at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
   at java.lang.Thread.run(Unknown Source)
[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 8:31 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
umm, either set those relationships to lazy="false" (the easy way) or load those collections inside a Session (the correct way)

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 26, 2007 6:31 am 
Newbie

Joined: Sun Sep 19, 2004 9:23 pm
Posts: 7
kochcp wrote:
umm, either set those relationships to lazy="false" (the easy way) or load those collections inside a Session (the correct way)


then,why the first code is connect?


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.