Could someone help me out on why I get the following exeception when trying to access the users set on my company?
Thanks!
org.hibernate.LazyInitializationException: illegal access to loading collection
Hibernate version: 3.0
Mapping documents: <hibernate-mapping> <class name="com.myorg.model.Company" table="company">
<id name="id" type="integer" column="company_id" > <generator class="native"/> </id> <property name="name" type="string" column="name" not-null="true"/> <set name="users" inverse="true" lazy="true"> <key column="company_id"/> <one-to-many class="com.myorg.model.User"/> </set>
</class> </hibernate-mapping>
<hibernate-mapping> <class name="com.myorg.model.User" table="[user]">
<id name="id" type="integer" column="user_id" > <generator class="native"/> </id> <property name="user_name" type="string" column="user_name" not-null="true" unique="true"/> <property name="email" type="string" column="email" not-null="true" unique="true"/> <property name="first_name" type="string" column="first_name" not-null="true"/> <property name="last_name" type="string" column="last_name" not-null="true"/> <property name="er_optin" type="boolean" column="er_optin" not-null="false"/> <property name="fi_optin" type="boolean" column="fi_optin" not-null="false"/> <property name="ib_pm_optin" type="boolean" column="ib_pm_optin" not-null="false"/> <property name="ib_ms_optin" type="boolean" column="ib_ms_optin" not-null="false"/> <property name="ib_ma_optin" type="boolean" column="ib_ma_optin" not-null="false"/> <property name="password" type="string" column="password" not-null="true"/> <property name="passwordExpDate" type="date" column="password_exp_date" not-null="false"/> <many-to-one name="company" column="company_id" class="com.myorg.model.Company" not-null="true"/> <set name="roles" lazy="true" table="user_role"> <key column="user_id"/> <many-to-many column="role_id" class="com.myorg.model.Role"/> </set> </class> </hibernate-mapping>
Code between sessionFactory.openSession() and session.close(): Company company = (Company) getHibernateTemplate().get(Company.class, id); Set users = company.getUsers(); int len = users.size();
Full stack trace of any exception that occurs: org.hibernate.LazyInitializationException: illegal access to loading collection [org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:172), org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48), org.hibernate.collection.PersistentSet.hashCode(PersistentSet.java:324), org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:297), org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:270), org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:200), org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:177), com.myorg.model.BaseObject.hashCode(BaseObject.java:27), org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:297), org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:270), org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:200), org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:177), com.myorg.model.BaseObject.hashCode(BaseObject.java:27), java.util.HashMap.hash(Unknown Source), java.util.HashMap.put(Unknown Source), java.util.HashSet.add(Unknown Source), java.util.AbstractCollection.addAll(Unknown Source), org.hibernate.collection.PersistentSet.endRead(PersistentSet.java:242), org.hibernate.engine.CollectionLoadContext.endLoadingCollection(CollectionLoadContext.java:183), org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:268), org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:249), org.hibernate.loader.Loader.endCollectionLoad(Loader.java:554), org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:541), org.hibernate.loader.Loader.doQuery(Loader.java:436), org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218), org.hibernate.loader.Loader.loadCollection(Loader.java:1434), org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111), org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488), org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60), org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430), org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:176), org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48), org.hibernate.collection.PersistentSet.size(PersistentSet.java:110), com.myorg.dao.hibernate.CompanyDAOHibernate.get(CompanyDAOHibernate.java:103), com.myorg.service.impl.CompanyServiceImpl.getCompany(CompanyServiceImpl.java:27), sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method), sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source), sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source), java.lang.reflect.Method.invoke(Unknown Source), org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287), org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181), org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148), org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96), org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170), org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176), $Proxy2.getCompany(Unknown Source), com.myorg.web.CompanyAction.edit(CompanyAction.java:105), sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method), sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source), sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source), java.lang.reflect.Method.invoke(Unknown Source), org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270), org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187), org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106), org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431), org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236), org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196), org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432), javax.servlet.http.HttpServlet.service(HttpServlet.java:709), javax.servlet.http.HttpServlet.service(HttpServlet.java:802), org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252), org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173), com.myorg.web.common.AuthorizationFilter.doFilter(AuthorizationFilter.java:105), org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202), org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173), org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174), org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77), org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202), org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173), org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213), org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178), org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126), org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105), org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107), org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148), org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869), org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664), org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527), org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80), org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684), java.lang.Thread.run(Unknown Source)
DB: SQL Server 2005
|