Hi All, I'm having some fun with Optimistic locking. Specifically, I'm trying to delete a series of objects contained in a collection, and getting the following error.
org.odmg.LockNotGrantedException: Object has been modified by someone else at org.apache.ojb.odmg.ObjectEnvelopeTable.commit(Unknown Source) at org.apache.ojb.odmg.TransactionImpl.doCommitOnObjects(Unknown Source) at org.apache.ojb.odmg.TransactionImpl.prepare(Unknown Source) at org.apache.ojb.odmg.TransactionImpl.commit(Unknown Source) at nz.ac.auckland.markit.netbeans.modules.property.propertyviews.MarkingMap View.commitTransaction(MarkingMapView.java:432) Now, I'm the only one using the db. I get the markingMap from the assessment, deep clone it (setting ID's to null), and let the users adjust it. When they've finished, I delete the entries in the existing markingMap for the assessment, then add the new entries to the db in their place. >From debugging and commenting out bits, adding the new entries works, but deleting the old ones doesn't. The existing MarkingMap entry objects aren't changed anywhere before I attempt to delete them. MarkingMap is a little special. Its basically a wrapped list of MarkeeData objects. And we're referring to it as part of the Assessment Object via the markingMap::list syntax. This has worked fine before we were using Optimistic Locking on it, so I'm not sure what's going on now :) In OJB.properties, ImplicitLocking is set to false and LockAssociations is set to read. Thanks for your help, Robert Relevant bits of the repository: <!-- nz.ac.auckland.markit.core.Assessment --> <class-descriptor class="nz.ac.auckland.markit.core.Assessment" table="Assessment"> <field-descriptor name="id" column="id" jdbc-type="INTEGER" primarykey="true" autoincrement="true"/> <field-descriptor name="ojbVersion" column="ojb_version" jdbc-type="INTEGER" locking="true"/> .... <collection-descriptor name="markingMap::list" element-class-ref="nz.ac.auckland.markit.core.MarkeeData" collection-class="nz.ac.auckland.markit.core.TypedSet" auto-retrieve="true" auto-update="false" > <inverse-foreignkey field-ref="id_Assessment"/> <orderby name="listIndex" sort="ASC"/> </collection-descriptor> </class-descriptor> <!-- nz.ac.auckland.markit.core.MarkeeData --> <class-descriptor class="nz.ac.auckland.markit.core.MarkeeData" table="MarkeeData"> <field-descriptor name="id" column="id" jdbc-type="INTEGER" primarykey="true" autoincrement="true"/> <field-descriptor name="ojbVersion" column="ojb_version" jdbc-type="INTEGER" locking="true"/> <field-descriptor name="id_Assessment" column="id_Assessment" jdbc-type="INTEGER"/> ... <reference-descriptor name="assessment" class-ref="nz.ac.auckland.markit.core.Assessment"> <foreignkey field-ref="id_Assessment"/> </reference-descriptor> </class-descriptor> And the original code: ... Transaction tx = PersistenceManager.getInstance().getODMG().newTransaction(); Database db = PersistenceManager.getInstance().getOdmgDb(); try{ //Make the new marking map (currMarkingMap) persistent for currAssessment tx.begin(); tx.lock(currAssessment, Transaction.WRITE); // delete the old marking map entries for (Iterator iter = currAssessment.getMarkingMap().getData().listIterator(); iter.hasNext();) { MarkeeData md = (MarkeeData)iter.next(); db.deletePersistent(md); iter.remove(); } // add the new entries currMarkingMap.setAssessment(currAssessment); // set all the new entry's assessments to point // to currentAssessment for(Iterator iter = currMarkingMap.getData().listIterator(); iter.hasNext();) { MarkeeData md = (MarkeeData)iter.next(); tx.lock(md, Transaction.WRITE); } currAssessment.setMarkingMap(currMarkingMap); // set the assessment's marking map to point here. tx.commit(); }catch(Exception e){ if (tx.isOpen()) tx.abort(); ErrorManager.getDefault().notify(e); } ... --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]