Hi. I had the same problem with deleteCollections. A defensive copy must
be done by OJB before returning the collection to the user in that case.
In your case I'm not sure what it is !

Here is the patch that solves my problem,Maybe you can try to fix your
problem based on this patch !






On Thu, 2003-10-16 at 14:07, R�da Benzair wrote:
> Hi All 
> 
> It seems OJB has a multi thread unsafe behaviour when handling M:N
> relations:
>  
> java.util.ConcurrentModificationException
>         at java.util.HashMap$HashIterator.nextEntry(HashMap.java:762)
>         at java.util.HashMap$KeyIterator.next(HashMap.java:798)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.deleteMtoNImplementor(P
> ersistenceBrokerImpl.java:970)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.storeCollections(Persis
> tenceBrokerImpl.java:785)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(PersistenceBr
> okerImpl.java:2007)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.store(PersistenceBroker
> Impl.java:1889)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.store(PersistenceBroker
> Impl.java:665)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.storeReferences(Persist
> enceBrokerImpl.java:692)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(PersistenceBr
> okerImpl.java:1954)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.store(PersistenceBroker
> Impl.java:1889)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.store(PersistenceBroker
> Impl.java:665)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.storeReferences(Persist
> enceBrokerImpl.java:692)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(PersistenceBr
> okerImpl.java:1954)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.store(PersistenceBroker
> Impl.java:1889)
>         at
> org.apache.ojb.broker.core.PersistenceBrokerImpl.store(PersistenceBroker
> Impl.java:665)
>         at
> org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(DelegatingP
> ersistenceBroker.java:160)
>         at
> org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(DelegatingP
> ersistenceBroker.java:160)
>  
> Replacing the use of an HashMap -unsynchro- with an Hashtable
> -synchronized- would solve the problem, wouldn't it?
>  
> This is a trouble that happens on a production system and i'm looking
> foward to hear about your response!
>  
> Thanks in advance!
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
-- 
Leandro Rodrigo Saad Cruz
IT - Inter Business Tecnologia e Servicos (IB)
http://www.ibnetwork.com.br
http://db.apache.org/ojb
http://xingu.sourceforge.net

Index: src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
===================================================================
RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
retrieving revision 1.38
diff -u -b -B -r1.38 PersistenceBrokerImpl.java
--- src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java	15 Oct 2003 15:41:10 -0000	1.38
+++ src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java	16 Oct 2003 18:33:36 -0000
@@ -588,14 +588,25 @@
                     Object col = cds.getPersistentField().get(obj);
                     if (col != null)
                     {
-
+                        System.out.println("collection type : " + col.getClass().getName());
                         if (col instanceof ManageableCollection)
                         {
-                            colIterator = ((ManageableCollection) col).ojbIterator();
+                            System.out.println("Duplicating collection");
+  
+                            ManageableCollection original = (ManageableCollection) col;
+                            ManageableCollection copy = new RemovalAwareCollection();
+                            copy.ojbAddAll(original);
+                            colIterator = copy.ojbIterator();
+//                            colIterator = ((ManageableCollection) col).ojbIterator();
                         }
                         else if (col instanceof Collection)
                         {
-                            colIterator = ((Collection) col).iterator();
+                            System.out.println("Duplicating collection");
+                            //LEANDRO: make a defensive copy to prevent ConcurrentModificationException
+                            Collection original = (Collection) col;
+                            Collection copy =new ArrayList(original.size());
+                            copy.addAll(original);
+                            colIterator = copy.iterator();
                         }
                         else if (col.getClass().isArray())
                         {
@@ -1072,6 +1083,7 @@
      */
     private void retrieveReference(Object obj, ClassDescriptor cld, ObjectReferenceDescriptor rds, boolean forced, HashMap retrievalTasks)
     {
+        logger.debug("RETRIEVING reference for["+cld.getClassNameOfObject()+"] on field ["+rds.getAttributeName()+"]");
         PersistentField refField;
         Object refObj;
         if (forced || rds.getCascadeRetrieve())
@@ -1104,6 +1116,7 @@
      */
     private void retrieveCollection(Object obj, ClassDescriptor cld, CollectionDescriptor cds, boolean forced, HashMap retrievalTasks)
     {
+        logger.debug("RETRIEVING collection for["+cld.getClassNameOfObject()+"] on field ["+cds.getAttributeName()+"]");
         if (forced || cds.getCascadeRetrieve())
         {
             if ((retrievalTasks != null) && !cds.isLazy() && !cds.isMtoNRelation()

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to