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.  [ 5 posts ] 
Author Message
 Post subject: ConcurrentModificationException during session.getEntityName
PostPosted: Fri Nov 17, 2006 1:42 pm 
Newbie

Joined: Tue Mar 01, 2005 11:39 am
Posts: 8
I am having an issue with calling session.getEntityName(obj) where a ConcurrentModificationException is thrown. This is occuring in some web application code where I am trying to save the objectId and entity name so that I can load the object again later if needed.

The process is basically:

# load object from hibernate
# call session.getEntityName(...) on the same session it was loaded from.

It is probably important to note that this same code executed in a junit test case works fine without the exception. When running under jetty I get the exception every time. I realize the error is likely to be in my web application setup and how it differs from my test setup but I would like some pointers on where I should start looking for issues as I can't think of what would cause this behavior.


Hibernate version:
3.2

Mapping documents:
<hibernate-mapping auto-import="true" package="com.pinklady.profile">

<class name="MyProfile" table="Profile">
<id name="id" column="userId">
<generator class="foreign">
<param name="property">user</param>
</generator>
</id>
<one-to-one name="user" constrained="true" />

<property name="firstName" not-null="false" unique="false" type="string" length="55" />
<property name="lastName" not-null="false" unique="false" type="string" length="55" />

<array name="urls" table="ProfileUrls">
<key column="userId" />
<index column="ndx" />
<element column="url" type="string" />
</array>

<list name="photos" access="field" cascade="all">
<key column="profileId" not-null="true" />
<index column="ndx" />
<one-to-many class="com.pinklady.Photo" />
</list>
</class>

</hibernate-mapping>

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

Object object = session.load(MyProfile.class, 1234);
String entityName = session.getEntityName(object);

Full stack trace of any exception that occurs:

java.util.ConcurrentModificationException
at org.apache.commons.collections.ReferenceMap$EntryIterator.checkMod(Unknown Source)
at org.apache.commons.collections.ReferenceMap$EntryIterator.hasNext(Unknown Source)
at java.util.AbstractMap.containsValue(AbstractMap.java:108)
at org.hibernate.engine.StatefulPersistenceContext.containsProxy(StatefulPersistenceContext.java:439)
at org.hibernate.impl.SessionImpl.getEntityName(SessionImpl.java:1737)
at com.pinklady.wicket.HibernateObjectModel.setHibernateObject(HibernateObjectModel.java:47)

Name and version of the database you are using:
Postgresql 8.1

The generated SQL (show_sql=true):

n.a

Debug level Hibernate log excerpt:

Doesn't appear to be anything interesting other than the MyProfile object being loaded successfully.


Thanks!

Ryan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 4:21 pm 
Newbie

Joined: Tue Mar 01, 2005 11:39 am
Posts: 8
Upon further inspection it looks like the object I am using to call getEntityName() (which comes from session.load(MyProfile.class, 1234) is a transient instance of MyProfile. it is strange that session.load(...) would return a transient instance... I am in the process of digging deeper.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 5:27 pm 
Newbie

Joined: Tue Mar 01, 2005 11:39 am
Posts: 8
The source if my issue revolves around:

<id name="id" column="userId">
<generator class="foreign">
<param name="property">user</param>
</generator>
</id>

in my mapping file. Performing session.load(MyProfile.class, integerId) works great if the profile was saved from that session. If it is saved from a different session it returns an empty proxy (inspecting the debug log output shows no query to the database is performed).

I will start a new thread with the source of the issue, perhaps I am doing this wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 7:30 pm 
Newbie

Joined: Tue Mar 01, 2005 11:39 am
Posts: 8
I take my previous statement back. Here is a simplified view of what causes the ConcurrentModificationException (CME):

Code:
Session session = sessionFactory.openSession();
MyProfile profile = (MyProfile) session.load(MyProfile.class, 1234);
//profile.getFirstName();
String entityName = session.getEntityName(profile);


If the commented line in the middle (profile.getFirstName()) remains commented the proxy has not been initialized with data from the database. Calling session.getEntityName(profile) causes the lazy initialization to happen while a collection is being iterated over (and a CME is thrown).

If the line is uncommented getFirstName() causes the lazy initialization to occur. Calling getEntityName(profile) now results in:

Code:
org.hibernate.TransientObjectException: proxy was not associated with the session
     at org.hibernate.impl.SessionImpl.getEntityName(SessionImpl.java:1738)


This is very strange to me because I just used the session to load that proxy! Why is this happening?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 8:43 pm 
Newbie

Joined: Tue Mar 01, 2005 11:39 am
Posts: 8
Found the a solution. In my mapping file I changed:

Code:
<class name="MyProfile" table="Profile">


To:

Code:
<class name="MyProfile" table="Profile" lazy="false">


I thought lazy properties were off by default in 3.x? Perhaps I need to look in my configuration to see if anything is setting that for me.

Further is hibernate doing the right thing by not adding a lazy loaded class into its list of proxies?


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