问题
Since upgrading to GAE 1.8, I'm getting scattered ids when annotating with @Id in Objectify:
@Id
private Long id;
Even though I understand the need for scattered ids in terms of avoiding hotspots on the cloud platform, is there a way in Objectify to get the old incremental ids back? Having to display a hexatridecimal value (like 1DZENH6BSOW) in the UI to avoid that massive generated 64bit id just doesn't cut it.
I'm happy to have a secondary annotation @IdLegacy working in conjunction with the @Id, then @Id will still generate the long id and I can use the legacy id for display purposes.
SOLUTION:
Inside my construtor, I have a simple piece of code that allocates an id if ones doesn't exist:
if (getId() == null){
ObjectifyFactory f = new ObjectifyFactory();
Key<MyEntity> key = f.allocateId(MyEntity.class);
setId(key.getId());
}
回答1:
As far as I know, Objectify passes along the App Engine Datastore's scattered id behavior.
A quick check of the Objectify issue tracker doesn't show that anyone has yet made a request for incremental ids. Submit a request to the Objectify devs. http://code.google.com/p/objectify-appengine/issues/list
来源:https://stackoverflow.com/questions/19152016/incremental-ids-on-objectify