Objectify - @Embed or create Ref<Entity>

205 views
Skip to first unread message

Daniel Peña Perez

unread,
Feb 14, 2014, 5:02:27 AM2/14/14
to objectify...@googlegroups.com
Hi all, I newbie with objectify ( before i have used JPA with datanucleous in gae projects ...)

What is better performance to save relationated objects with objectify?.

Option1
@Entity
public class Entity1{
 private Entity2 ent2;
}

@Embed
public class Entity2{
 private String prop;
}
On the one hand @Embed mechanism write all embed data into Entity1 and can be accesible by query to Entity1 entity with syntax ->" ent2.prop= "value"
This mechanism only need one operation to write entire relation objects.
and need only one operation to query
In some test I found that is slower than save child entity with <Ref>....
My test looks like this:

ofy().save().entity(mainEntity).now();
ofy().load().type(mainEntity.class).list() ;  --> Some times this query get size 0 (Maybe datastore is not prepared for quer so quickly....but i use .now()  on save....) ;-(


Option2
On the other hand I can save 2 entities,
the "relatedEntity" and the Ref<RelatedEntity> in main entity
this cost 2 operations to write and to query for, but in my test always works fine.


What do you think is the better way to store relations?

Thanks in advance guys!!




Jeff Schnitzer

unread,
Feb 14, 2014, 11:33:07 AM2/14/14
to objectify...@googlegroups.com
ofy().load().type(mainEntity.class).list();

is an eventually consistent query. As would your other query unless
you specify an ancestor(). Note that you can specify an ancestor() in
the above query, in which case you will get back the single entity.
See this:

https://developers.google.com/appengine/docs/java/datastore/structuring_for_strong_consistency

Most of the time in this case you are better off embedding the data...
but it depends on your query profile and the shape of the data.

Jeff
> --
> You received this message because you are subscribed to the Google Groups
> "objectify-appengine" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to objectify-appen...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages