I have the following entities:
@Entity
public class Person {
@Id public Long id;
public String name;
public Ref<Picture> picture;
public String email;
public byte age;
public short birthday; // day of year
public String school;
public String very_long_life_story;
... some extra fields ...
}
@Entity
public class Place {
@Id public Long id;
public String name;
public String comment;
public long createdDateMS;
public long visitors;
@Load public List<Ref<Person>> owners;
}
Few notes: (A) Maximum size of owners, in Place entity, is 4 (~) (B) The person class is presumable very big, and when querying place, I would like to only show a subset of the person data. This optimizations is aimed both at server-client and server-database communications. Since objectify (gae actually) only load/save entire entities, I would like to do the following:
@Entity
pubilc class PersonShort {
@Id public Long id;
public Ref<Picture> picture;
public String name;
}
and inside Place, I would like to have (instead of owners):
@Load public List<PersonShort> owners;
(C) The problem with this approach, is that now I have a duplication inside the datastore. Although this isn't such a bad thing, the real problem is when a Person will try to save a new picture, or change name; I will not only have to update it in his Person class, but also search for every Place that has a PersonShort with same id, and update that.
(D) So the question is, is there any solution? Or am I simply forced to select between the options? (1) Loading multiple Person class, which are big, when all I need is some really small information about it. (2) Data duplication with many writes
If so, which one is better (Currently, I believe it's 1)?
EDIT What about loading the entire class (1), but sending only part of it?
@Entity
public class Person {
@Id public Long id;
public String name;
public Ref<Picture> picture;
public String email;
public byte age;
public short birthday; // day of year
public String school;
public String very_long_life_story;
... some extra fields ...
}
public class PersonShort {
public long id;
public String name;
}
@Entity
public class Place {
@Id public Long id;
public String name;
public String comment;
public long createdDateMS;
public long visitors;
// Ignore saving to datastore
@Ignore
public List<PersonShort> owners;
// Do not serialize when sending to client
@ApiResourceProperty(ignored = AnnotationBoolean.TRUE)
@Load public List<Ref<Person>> ownersRef;
@OnLoad private void loadOwners() {
owners = new List<PersonShort>();
for (Ref<Person> r : ownersRef) {
owners.add(nwe PersonShort(r.get()));
}
}
}