I have a "Student" entity type which is persistent. It is of many-to-
many relationship with "Team" entity type. Moreover, its keys are
stored in "List<Key> submittedStudentsKeys;" in "EvaluationTeam"
entity type

In one word, if I want to delete a "Student" tuple, I not only need to
remove the target object, but also remove all the traces of this
object in objects of other types.

                Key stuKey = KeyFactory.stringToKey(req.getParameter("stuKey"));
                PersistenceManager pm = PMF.get().getPersistenceManager();
                Student stu = pm.getObjectById(Student.class,stuKey);
                String stuName = stu.getName();
                List<Key> teamKeys = stu.getTeams();

                try {
                        for (Key teamKey: teamKeys){
                            Team team = pm.getObjectById(Team.class, teamKey);
                            List<Key> teamEvalKeys = team.getEvaluationTeams();
                            for (Key teamEvalKey : teamEvalKeys){
                                EvaluationTeam et = 
pm.getObjectById(EvaluationTeam.class,
teamEvalKey);
                                List<EvalDetail> edsToBeRemoved = new 
ArrayList<EvalDetail>();
                                for (EvalDetail ed: et.getEvalDetails()){
                                        if 
(!ed.isSelfEval()&&ed.getTo().equals(stuName)) {
                                                edsToBeRemoved.add(ed);
                                                continue;
                                        }
                                        if (ed.getFrom().equals(stuName)){
                                                edsToBeRemoved.add(ed);
                                                continue;
                                        }
                                }
                                pm.deletePersistentAll(edsToBeRemoved);//remove 
all
evalDetails relevant to this student
                                
et.getSubmittedStudents().remove(stuKey);//remove student key
from submitted students
                            }
                            team.getStudents().remove(stuKey);//remove student 
from this
team
                        }
                        pm.deletePersistent(stu);//remove student object
                } finally {
                        pm.close();
                }

However, the above action only removes the Student object. The
List<Key> in "Team" does not remove the key of the target Student
object. Same for "et.getSubmittedStudents()"

My Question is:
If I store an entity with one attribute "List<Sth> sths", how do I
remove an item from list?

Retrieving the list from datastore and use "remove()" on the list does
not work.

-- 
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 google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to