views:

20

answers:

1

I'm using the appengine datastore, and all of my entities have Long ids as their PrimaryKey. I use those ids to communicate with the client, since the full-fledged Keys take much more bandwidth to transmit.

Now, I want to form entity groups so that I can do complex operations within transactions, and it seems from http://code.google.com/appengine/docs/java/datastore/transactions.html#Entity_Groups that I need to use Keys or String encoded keys - the simple Longs are not an option.

I don't mind refactoring a little to use Keys, but I still want to avoid sending the behemoth things over the wire. How can I get a unique (per kind) Long identifier for an entity whose primary key is a Key?

+3  A: 

You do not have to use names (strings). All of the KeyBuilder methods that take names also have counterparts that take ids (longs).

For transmission, you simply need the name or id part of a Key. Once you know the id or name, you can reconstruct the Key server side. If it is a child entity, you'll need to know both the parent and the child's names or ids.

Robert Kluin