-->
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.  [ 4 posts ] 
Author Message
 Post subject: LazyInitializationException:19 - illegal access to loading
PostPosted: Thu Oct 20, 2005 11:26 pm 
Newbie

Joined: Thu Oct 20, 2005 10:54 pm
Posts: 2
I'm using Spring and Hibernate

LazyInitializationException:19 - illegal access to loading collection.

I get above exception when trying to access the size of the detail collection set. ((WVmi945m)returnedList.get(0)).getWVmi945dSet().size();

I have tried using
Hibernate.initialize(((WVmi945m)returnedList.get(0)).getWVmi945dSet());
but i get the same exception.

I have set my mapping file to lazy="true" and I'm not getting session closed exception? I don't understand why it is illegal to access the collection.

I have searched the forum and the web and have tried everything but I still get the ERROR


Can somebody please help me and tell me what i'm doing wrong?

Thanks in advance. :)

Best Regards,

Muyen


public List find_Wvmi945m() throws Exception{



return (List)getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException {


String query = "from WVmi945m w945 where w945.serialno= 3348";
List returnedList = getHibernateTemplate().find(query);
((WVmi945m)returnedList.get(0)).getWVmi945dSet().size();
return returnedList;

}
});

}


Hibernate version:hibernate-3.0.5

Mapping documents:
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Sat Sep 24 17:41:18 CST 2005 -->
<hibernate-mapping package="vmi.msg.bo">

<class name="WVmi945m" table="W_VMI945M" lazy="false">

<id name="serialno" column="SERIALNO" type="long">

</id>

<property name="fk940m" column="FK_940M" type="long"
not-null="true" />
<property name="recordtype" column="RECORDTYPE" type="string"
not-null="true" />
<property name="plantcode" column="PLANTCODE" type="string"
not-null="true" />
<property name="vmino" column="VMINO" type="string"
not-null="true" />
<property name="numofdetail" column="NUMOFDETAIL" type="short"
not-null="true" />
<property name="owner" column="OWNER" type="string"
not-null="true" />
<property name="pullsignalno" column="PULLSIGNALNO"
type="string" not-null="true" />
<property name="orderdate" column="ORDERDATE" type="calendar"
not-null="true" />
<property name="goodreceipient" column="GOODRECEIPIENT"
type="string" />
<property name="specialinstruction" column="SPECIALINSTRUCTION"
type="string" />
<property name="timestamp" column="TIMESTAMP" type="calendar"
not-null="true" />

<set name="WVmi945dSet" lazy="true" inverse="true"
cascade="all">
<key>
<column name="FK_945M" />
</key>

<one-to-many class="vmi.msg.bo.WVmi945d" />
</set>

</class>

</hibernate-mapping>

<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Sat Sep 24 17:41:17 CST 2005 -->
<hibernate-mapping package="vmi.msg.bo">

<class name="WVmi945d" table="W_VMI945D" lazy="true" >

<id name="serialno" column="SERIALNO" type="long" unsaved-value="0">
<generator class="native"/>
</id>

<property name="recordtype" column="RECORDTYPE" type="string" not-null="true" />
<property name="plantcode" column="PLANTCODE" type="string" not-null="true" />
<property name="vmino" column="VMINO" type="string" not-null="true" />
<property name="pullsignalno" column="PULLSIGNALNO" type="string" not-null="true" />
<property name="itemno" column="ITEMNO" type="string" not-null="true" />
<property name="vendorpart" column="VENDORPART" type="string" />
<property name="vrcode" column="VRCODE" type="string" not-null="true" />
<property name="iecpocode" column="IECPOCODE" type="string" not-null="true" />
<property name="iecpoitem" column="IECPOITEM" type="string" not-null="true" />
<property name="iecpartno" column="IECPARTNO" type="string" not-null="true" />
<property name="pullqty" column="PULLQTY" type="long" not-null="true" />
<property name="unitofmeasure" column="UNITOFMEASURE" type="string" not-null="true" />
<property name="receivingloc" column="RECEIVINGLOC" type="string" />
<property name="qcindicator" column="QCINDICATOR" type="string" />
<property name="timestamp" column="TIMESTAMP" type="calendar" not-null="true" />

<many-to-one
name="WVmi945m"
class="vmi.msg.bo.WVmi945m"
not-null="true">
<column name="FK_945M" />
</many-to-one>
</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
10:45:54,375 ERROR LazyInitializationException:19 - illegal access to loading collection
org.hibernate.LazyInitializationException: illegal access to loading collection
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:172)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
at org.hibernate.collection.PersistentSet.hashCode(PersistentSet.java:324)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:348)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionAppend(HashCodeBuilder.java:309)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:283)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:150)
at vmi.msg.bo.VmiMsg.hashCode(VmiMsg.java:13)
at org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:348)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionAppend(HashCodeBuilder.java:309)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:283)
at org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:150)
at vmi.msg.bo.VmiMsg.hashCode(VmiMsg.java:13)
at java.util.HashMap.hash(HashMap.java:264)
at java.util.HashMap.put(HashMap.java:382)
at java.util.HashSet.add(HashSet.java:194)
at java.util.AbstractCollection.addAll(AbstractCollection.java:318)
at org.hibernate.collection.PersistentSet.endRead(PersistentSet.java:242)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollection(CollectionLoadContext.java:183)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:268)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:249)
at org.hibernate.loader.Loader.endCollectionLoad(Loader.java:554)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:541)
at org.hibernate.loader.Loader.doQuery(Loader.java:436)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1434)
at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1430)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:176)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:48)
at org.hibernate.collection.PersistentSet.size(PersistentSet.java:110)
at vmi.dao.impl.MessageDaoImpl$3.doInHibernate(MessageDaoImpl.java:535)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:358)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:331)
at vmi.dao.impl.MessageDaoImpl.find_Wvmi945m(MessageDaoImpl.java:528)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:163)
at $Proxy1.find_Wvmi945m(Unknown Source)
at test.dao.impl.MessageDaoImplTest.testFindPullSignal(MessageDaoImplTest.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196


Name and version of the database you are using: Oracle 8

The generated SQL (show_sql=true): Hibernate: select wvmi945dse0_.FK_945M as FK17_1_, wvmi945dse0_.SERIALNO as SERIALNO1_, wvmi945dse0_.SERIALNO as SERIALNO0_, wvmi945dse0_.RECORDTYPE as RECORDTYPE11_0_, wvmi945dse0_.PLANTCODE as PLANTCODE11_0_, wvmi945dse0_.VMINO as VMINO11_0_, wvmi945dse0_.PULLSIGNALNO as PULLSIGN5_11_0_, wvmi945dse0_.ITEMNO as ITEMNO11_0_, wvmi945dse0_.VENDORPART as VENDORPART11_0_, wvmi945dse0_.VRCODE as VRCODE11_0_, wvmi945dse0_.IECPOCODE as IECPOCODE11_0_, wvmi945dse0_.IECPOITEM as IECPOITEM11_0_, wvmi945dse0_.IECPARTNO as IECPARTNO11_0_, wvmi945dse0_.PULLQTY as PULLQTY11_0_, wvmi945dse0_.UNITOFMEASURE as UNITOFM13_11_0_, wvmi945dse0_.RECEIVINGLOC as RECEIVI14_11_0_, wvmi945dse0_.QCINDICATOR as QCINDIC15_11_0_, wvmi945dse0_.TIMESTAMP as TIMESTAMP11_0_, wvmi945dse0_.FK_945M as FK17_11_0_ from W_VMI945D wvmi945dse0_ where wvmi945dse0_.FK_945M=?

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: I have found out the problem but don't know the real cause
PostPosted: Fri Oct 21, 2005 10:50 pm 
Newbie

Joined: Thu Oct 20, 2005 10:54 pm
Posts: 2
After being very annoying but the exception, I decided to use the debug mode and traced the source. I finally found out the exception was coz by set.addAll(tempList)

PresistantSet class
public boolean endRead() {
set.addAll(tempList); <-----
tempList = null;
setInitialized();
return true;
}

then i remembered, i added following code to my base BO object

It is apachee common lang HashCodeBuilder

public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}



After I removed the method... everthing works.......
I'm not sure why the hashCode would coz an instable state for the tempList.

Maybe someone can help me out on this question


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 3:48 pm 
Regular
Regular

Joined: Wed May 11, 2005 11:57 pm
Posts: 80
There is a loop somewhere in the process. Object obj is being lazily loaded, and somewhere in the lazy loading process, something is referring to obj, which is invalid because it's not loaded yet.


Top
 Profile  
 
 Post subject: Re: I have found out the problem but don't know the real cau
PostPosted: Wed Oct 26, 2005 5:18 pm 
Newbie

Joined: Mon Oct 17, 2005 3:42 pm
Posts: 17
muyen wrote:
I'm not sure why the hashCode would coz an instable state for the tempList.

Maybe someone can help me out on this question


the reflective hashcode widget is probably trying to iterate the collection, which accesses it, but it's not done initializing because it needs its hashcode.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.