0
votes

When saving a Objectify Entity to the Appengine datastore, is it possible to save a custom Datastore "Key" instead of the auto generated Key hash?

1
No, why would you want to do that? - Rick Mangi

1 Answers

2
votes

You can use any String or long and annotate it as being the key, like this:

import javax.persistence.Id;

public class MyEntityClass {
  @Id
  private String myCustomKey;

  public MyEntityClass(String keyId) {
    this.myCustomKey = keyId;
  }
}

Then you can retrieve it again using:

MyEntityClass object = ofy().get(new Key<MyEntityClass>(MyEntitiyClass.class, "specificKeyId"));