简体   繁体   English

使用Google App Engine数据存储区中的实体列表

[英]Using lists of entities in Google App Engine Datastore

I am using objectify with Google App Engine (backed by their datastore project). 我在Google App Engine(由他们的数据存储项目支持)中使用objectify。 I am a little confused on how lists of entities work. 我对实体列表的工作方式有些困惑。

I have some Student entities, and I have some Teacher entities. 我有一些学生实体,还有一些教师实体。

I want the Teacher to have a students property that is List of Student entities. 我希望教师拥有一个学生属性,即“ 学生实体”列表。

It seems easy and it seems to work ok. 看起来很容易,而且看起来还可以。 However, I just noticed today that when I modify a property of a Student , it doesn't seems to update the Student in the various Teacher 's students List. 但是,我今天才注意到,当我修改Student的属性时,似乎并没有更新各个Teachers 学生列表中的Student For example, if I change a student's name and save it, the student list from a teacher will still have its old name. 例如,如果我更改了一个学生的名字并保存了它,则老师的学生列表仍将使用其旧名字。 It is almost as if the teacher has its own local version of that object. 几乎就像老师拥有该对象的本地版本一样。

Is that correct? 那是对的吗? Is there any way that I can get the actual object stored? 有什么办法可以存储实际的对象? Or do I have to do something like just store the IDs? 还是我必须做一些事情,例如只存储ID?

Any help would be appreciated. 任何帮助,将不胜感激。

Here are the classes, for reference: 以下是类,以供参考:

@Entity
@Index
public class StudentObj {
    @Id public Long id;
    public String StudentName;
}

@Entity
@Index
public class TeacherObj {
    @Id public Long id;
    public String TeacherName;
    public List<StudentObj> students;
}

Thanks in advance! 提前致谢!

By using List<Student> , you are embedding the student data in the teacher object. 通过使用List<Student> ,您可以将学生数据嵌入到教师对象中。 To create a link to an independent entity, store a List<Key<Student>> or a List<Ref<Student>> in your teacher. 要创建到独立实体的链接,请将List<Key<Student>>List<Ref<Student>>在您的老师中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM