On Fri, Mar 5, 2010 at 12:34 AM, Nacho Coloma <icol...@gmail.com> wrote:
>>
>> Having an id field instead of a key makes queries easier.  With
>> Objectify, you can create a query without needing to know that the id
>> is part of a key field:
>>
>> query.filter("id >", 5000).sort("-id")
>
> This would only work  with root entities, which are a minority. The
> most common case is like this:
>
>> class MyEntity {
>>     @Id Long id;
>>     @Parent Key<ParentEntity> owner;
>> }

About this I must disagree.  Everything I've learned about the
appengine datastore says that unless you specifically need
transactions, you should avoid using parent entities.

When any entity is written, the optimistic concurrency journal is
maintained for the root of the entity group.  If you make writes all
over a large entity graph, they will all contend for the same journal,
diminishing throughput.

Even if throughput isn't an issue, parent keys are cumbersome to deal
with.  They should not be the general case.

> This _is_ redundant since internally GAE stores the owner inside the
> Key field. So we settled for the simplest solution, that was to make
> visible the Key system used by GAE. It also makes getting by primary
> key more efficient, since you don't have to pass the class.

You completely lost me with this one.  What's more efficient?  Using
the datastore Key class means you get no help from the compiler.  If
you pass Key objects around through methods you can very quickly lose
track of what those keys are supposed to point to!  The generic
Key<MyEntity> may require a little more typing but it will
significantly reduce the probability of bugs.

> I don't like it either, but GAE allows to have several transactions
> open at the same time, affecting different shards. We wanted to
> support that.
>
> The way JDO circumvents this is by using several PersistenceManager
> instances, but that seems weird to me.

Objectify handles this by letting you create multiple Objectify
instances.  Quite easy:

Objectify ofy1 = ObjectifyService.beginTransaction();
Objectify ofy2 = ObjectifyService.beginTransaction();

Foo foo = ofy1.get(Foo.class, 123);
Bar bar = ofy2.get(Bar.class, 987);

The transaction is bound to the object instance.  You can merrily work
with ofy1 and ofy2 in separate transactions.

Jeff

-- 
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