Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 72049 invoked from network); 12 Dec 2004 17:11:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 12 Dec 2004 17:11:30 -0000 Received: (qmail 73263 invoked by uid 500); 12 Dec 2004 17:11:29 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 73234 invoked by uid 500); 12 Dec 2004 17:11:29 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 73219 invoked by uid 99); 12 Dec 2004 17:11:29 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of jbraeuchi@gmx.ch designates 213.165.64.20 as permitted sender) Received: from mail.gmx.net (HELO mail.gmx.net) (213.165.64.20) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 12 Dec 2004 09:11:28 -0800 Received: (qmail 14801 invoked by uid 65534); 12 Dec 2004 17:11:25 -0000 Received: from adsl-62-167-60-94.adslplus.ch (EHLO [192.168.1.10]) (62.167.60.94) by mail.gmx.net (mp016) with SMTP; 12 Dec 2004 18:11:25 +0100 X-Authenticated: #15507884 Message-ID: <41BC7B11.6050409@gmx.ch> Date: Sun, 12 Dec 2004 18:08:33 +0100 From: Jakob Braeuchi User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de-AT; rv:1.7.3) Gecko/20040910 X-Accept-Language: de, en MIME-Version: 1.0 To: OJB Developers List Subject: Re: Bug and proposed patch References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N hi tino, just to make sure: your test-case is actually a 1:n collection. how does your test differ from CollectionTest#testDeleteCollection or CollectionTest#testDeleteMainObjectWithOneToNRelation ? in these testcases a main-object is deleted with it's associated 1:n children (when auto-delete = object). jakob Tino Sch�llhorn schrieb: > Hi, > > yesterday I posted a problem in the user-list (Deleting Main-Object and > its association-objects). Currently there are no answers for this > message. I looked further at the code of OJB. The method which is > interesting at this point is > PersistenceBrokerImpl.deleteCollections(Object, List). > > Suppose you have the following case: Persons work at Projects with an > associated Role. Now if you are deleting a Person-Object or a > Project-Object you want to delete the corresponding Role-objects as well. > > Normally one can achieve that with *auto-delete=object* at the > collections for the role-objects. But the current implementation does > not work here correctly. If one has 3 or more role objects to be handled > one gets a ConcurrentModificationException, like this one (line numbers > have changed because of some change from me): > > java.util.ConcurrentModificationException > at > java.util.AbstractList$Itr.checkForComodification(AbstractList.java:448) > at java.util.AbstractList$Itr.next(AbstractList.java:419) > at > org.apache.ojb.broker.core.PersistenceBrokerImpl.deleteCollections(PersistenceBrokerImpl.java:701) > > at > org.apache.ojb.broker.core.PersistenceBrokerImpl.doDelete(PersistenceBrokerImpl.java:514) > > at > org.apache.ojb.broker.core.PersistenceBrokerImpl.delete(PersistenceBrokerImpl.java:466) > > at > org.apache.ojb.broker.core.DelegatingPersistenceBroker.delete(DelegatingPersistenceBroker.java:170) > > at > org.apache.ojb.broker.core.DelegatingPersistenceBroker.delete(DelegatingPersistenceBroker.java:170) > > at kos.generator.DataObject.delete(DataObject.java:106) > at > kos.intranet2.sandbox.DeletePersonTest.runTest(DeletePersonTest.java:64) > at > kos.intranet2.sandbox.DeletePersonTest.main(DeletePersonTest.java:98) > > > The current implementation looks like: > > if (cds.getCascadingDelete() == bjectReferenceDescriptor.CASCADE_OBJECT) { > Object col = cds.getPersistentField().get(obj); > if (col != null) > { > while (colIterator.hasNext()) > { > doDelete(colIterator.next()); > } > } > } > > And the ConcurrentModificationException is thrown at the call of doDelete. > > If a am using OJB correctly this use-case should work. So I propose the > following (but perhaps imperformant and inelegant) patch: The idea is > simple. Instead of deleting the object immediately from its > origin-collection, copy the elements to another collection an use this > for deleting. > > if (cds.getCascadingDelete() == bjectReferenceDescriptor.CASCADE_OBJECT) { > Object col = cds.getPersistentField().get(obj); > if (col != null) > { > // Inelegant and brutal. but it works > Collection c = new java.util.ArrayList(); > while (colIterator.hasNext()) { > c.add(colIterator.next()); > } > Iterator j = c.iterator(); > while (j.hasNext()) > { > doDelete(j.next()); > } > } > } > > So do you think you could apply this patch - or am I mistaken and I am > using OJB in a wrong way? > > With regards > Tino > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org > For additional commands, e-mail: ojb-dev-help@db.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org