August Detlefsen wrote: > Hi, I am getting the following error when I try to remove objects from an > ArrayList: > > org.exolab.castor.jdo.TransactionAbortedException: > Nested error: java.lang.IllegalStateException: Object deleted waiting > for lock?????????: Object deleted waiting for lock????????? > at > org.castor.persist.AbstractTransactionContext.prepare(AbstractTransactionContext.java:1227) > at > org.exolab.castor.jdo.engine.LocalDatabaseImpl.commit(LocalDatabaseImpl.java:161) > at > com.codemagi.servlets.content.PageController.dispatchSetTeam(PageController.java:1026) > > One > of my mapped objects, Section, contains an ArrayList of Users. When I > try to remove Users from that list and commit, I get the error. Here is > the code that causes the error to happen: > > Section section = (Section)db.load(Section.class, sectionId); Given that you have access to all Users associated with a Section through the getTeamMembers() method of Section, why not iterate through the list returned and remove User instances from this list as needed ?
Castor - upon commit time - will be able to tell that you have modified the list of team members, and persist things accordingly. [I am not 100% sure why your problem is occuring, but you are essentially loading some User instances more than once, though Castor should be able to deal with this.} I hope this helps Werner > > Iterator i = removeIds.iterator(); > while (i.hasNext()) { > Integer memberId = convertInteger( (String)i.next() ); > IUser memberToRemove = (IUser)db.load(USER_CLASS, memberId); > > section.removeUser(memberToRemove); //calls ArrayList.remove(Object) > } > > db.commit(); > > If > I log the contents of the List in section, I can see that the User > objects are getting properly removed. The actual error occurs when > db.commit() is called. > > What causes this error to be thrown? > How does one properly remove objects from a list? Note that we don't > actually want to delete the User, we just want to remove it from the > Section. > > Here is the mapping for Section showing a many-many relationship to User (the > database is MySQL): > > <class name="com.codemagi.servlets.content.model.Section" identity="id" > key-generator="IDENTITY"> > <description>section hierarchy for navigation and > breadcrumbs</description> > <map-to table="nav_section" /> > <field name="id" type="integer"> > <sql name="section_id" type="integer"/> > </field> > <field name="name" type="string"> > <sql name="section_name" type="varchar"/> > </field> > <field name="teamMembers" type="org.openeco.login.model.User" > collection="arraylist"> > <sql name="user_id" many-table="nav_section_user_xref" > many-key="section_id" /> > </field> > </class> > > Thanks, > August > > PS: Check out OpenEco. It is a full web application framework that uses > Castor JDO-XML as its core persistence layer: http://openeco.dev.java.net > > > > ____________________________________________________________________________________ > Be a better friend, newshound, and > know-it-all with Yahoo! Mobile. Try it now. > http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email