-->
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.  [ 2 posts ] 
Author Message
 Post subject: ConcurrentModificationExceptio iterating nested collections.
PostPosted: Fri Dec 09, 2005 8:37 pm 
Newbie

Joined: Tue Mar 01, 2005 4:13 pm
Posts: 7
What is the best practice for iterating nested collections.

I get ConcurrentModificationException when attempted to iterate a nested
collection.

I don't understand.

Thanks in advance.

3.05:

Mapping documents:

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC

"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">




<hibernate-mapping>

<class name="com.tests.A">
<id name="orderNumber" column="orderNumber" type="string">
<generator class="assigned"/>
</id>
<list name="bList" cascade="all" lazy="true">
<key column="parentId"/>
<list-index column="collIndex"/>
<many-to-many class="com.htg.tests.B"/>
</list>
</class>

</hibernate-mapping>


<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC

"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">




<hibernate-mapping>

<class name="com.htg.tests.B">
<id name="Key" column="id" type="string">
<generator class="uuid.hex"/>
</id>
<list name="cList" cascade="all" lazy="true">
<key column="parentId"/>
<list-index column="collIndex"/>
<many-to-many class="com.tests.C"/>
</list>
</class>

</hibernate-mapping>

<hibernate-mapping>
<id name="Key" column="id" type="string">
<generator class="uuid.hex"/>
</id>
<class name="com.htg.tests.C">
<property name="state"/>
</class>
</hibernate-mapping>


l

tx = sess.beginTransaction();

List aColl = sess.createQuery("from A as order").list();

for(int i = 0;i< aColl.size();i++){
A a = (A) aColl.get(i);
List bColl = a.getBList();
for(int j = 0;j< bColl.size();j++){
B b = (B) bColl.get(i);
List cColl = b.getCList();

for(int k = 0;k< cColl.size();k++){
C c = (C) cColl.get(k);
if(c.getState() == true){
break;//: This results in a ConcurrentModificationException
//: When the transaction is committed.
}
}
}
}


Full stack trace of any exception that occurs:
Root cause:
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:782)
at java.util.HashMap$ValueIterator.next(HashMap.java:812)
at org.hibernate.pretty.Printer.toString(Printer.java:90)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:91)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)

Name and version of the database you are using:
MySQL 5.0
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
Code:
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 8:01 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
It looks like a bug in "org.hibernate.pretty.Printer", debugger must help to find it.


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