Hello
I want to change order of objects in a collection, and then to change
some fields of those items. Unfortunately the items somehow become
'deleted'.
This is what I do...
--
if(someCondition)
{
// events in the original order (mainEvent is not instance of the
Event sub/class BTW)
List<Event> subEvents = mainEvent.getSubEvents();
// re-order the events {
Map<Key, Event> eventMap = new HashMap<Key, Event>();
for(Event event : subEvents)
eventMap.put(event.getKey(), event);
List<Event> eventsOrdered = new LinkedList<Event>();
JSONArray keysOrdered = new
JSONArray(request.getParameter("order"));
Key eventKey;
for(int i = 0; i < keysOrdered.length(); i++)
{
eventKey = KeyFactory.stringToKey(keysOrdered.getString(i));
eventsOrdered.add(eventMap.put(eventKey, eventMap.get(eventKey)));
}
// }
// put re-ordered items back in their place {
subEvents.clear();
subEvents.addAll(eventsOrdered);
// }
persistenceManager.makePersistent(mainEvent);
/*
* here ends the block in which mainEvent exists,
* the list of its items exists in parent scope in itemsOrdered
variable
*/
itemsOrdered = subEvents;
}
else
itemsOrdered = getItemsUsingAlternateApproach();
--
Now when I try to set a field on any of the items I get "Cannot write
fields to a deleted object".
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.