-->
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: illegal access to loading collection
PostPosted: Thu Jul 27, 2006 7:35 pm 
Newbie

Joined: Fri Jun 02, 2006 2:49 pm
Posts: 13
I am attemptying to make my collection non-lazy(and thus initilize all the elemtns), so I can pass it off to a swing interface.
Viewing the logs I can see hibernate placing items into the collection elements (EnumerationOptions)

DEBUG [org.hibernate.engine.TwoPhaseLoad] done materializing entity [com.EnumerationOptions#1336]

I also get

DEBUG [org.hibernate.engine.CollectionLoadContext] 15 collections were found in result set for role: com.EnumerationTypes.options

and directly after

ERROR [org.hibernate.LazyInitializationException] illegal access to loading collection
org.hibernate.LazyInitializationException: illegal access to loading collection

I use this to retrive the enumerationTypes

Session session = factory.openSession();
Criteria criteria = session.createCriteria(EnumerationTypes.class);
criteria.add( Restrictions.eq("tableName",tableName));
criteria.list();

The exception is throw during the .list() call.

I am using this as my mapping file

<hibernate-mapping>
<class name="com.EnumerationTypes" table="ENUMERATION_TYPES" lazy="false">
<id name="id" column="ID"/>
<property name="tableName" type="java.lang.String" column="TABLE_NAME"/>
<property name="columnName" type="java.lang.String" column="COLUMN_NAME"/>

<set name="options" batch-size="30" lazy="false">
<key column="TYPE_ID"/>
<one-to-many class="com.EnumerationOptions"/>
</set>
</class>
<class name="com.EnumerationOptions" table="ENUMERATION_OPTIONS">
<id name="id" column="ID"/>
<property name="name" type="java.lang.String">
<column name="NAME"/>
</property>
<property name="description" type="java.lang.String">
<column name="DESCRIPTION"/>
</property>

<property name="bitValue" type="java.lang.Integer">
<column name="BITVALUE"/>
</property>
<property name="visible" type="java.lang.Integer">
<column name="VISIBLE"/>
</property>

<many-to-one name="type" column="TYPE_ID" class="com.EnumerationTypes"/>
</class>
</hibernate-mapping>

I have looked all day and still have no idea what "illegal access to loading collection" means. I did look through some source and saw it is thrown when a collection is initialized while it's being initialized by something else.


Last edited by jamesconf on Thu Jul 27, 2006 9:00 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 27, 2006 8:09 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That means that you have an interceptor or event handler that's modifying the set as it's being loaded, or there's a set method in the class that's inside the collection that modifies the element on load, or maybe that the set method in the containing class modifies the collection during the set. The collection is set into the containing class when it's created; it might not be fully loaded at that point.

If it's not an interceptor or event handler, check all your set methods. They shouldn't do anything except set the parameter into the member. Stuff like this is not allowed:
Code:
public void setCollection(Collection col)
{
  this.col = col;
  this.col.add(new Thing("This is a placeholder"));
}
That modifies the collection, even though the collection hasn't yet been loaded.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: Yes that Pointed me to the right place
PostPosted: Mon Jul 31, 2006 5:11 pm 
Newbie

Joined: Fri Jun 02, 2006 2:49 pm
Posts: 13
I started looking into what would cause the class to be modifyed, I finely found it in the hashCode function. I was using HashCodeBuilder.reflectionHashCode()... and this is a bi-direction relationship.

Oddly the person who used the hashCode function says it was recomended in the hibernate docs.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 31, 2006 5:29 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The hashCode function is: there are many classes that must implement it (composite id classes and classes to be put into sets, for example). However, an automated hashcode calculator that works using reflection shouldn't be recommended anywhere. It's too likely to try to traverse the entire graph of connected entities, or else get stuck on an uninstantiated CGLib proxy object.

_________________
Code tags are your friend. Know them and use them.


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.