Incremental IDs on Objectify

荒凉一梦 提交于 2019-12-08 07:24:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!