Objectify上的增量ID [英] Incremental IDs on Objectify
问题描述
自从升级到GAE 1.8后,在Objectify中使用@Id进行注释时,我得到零散的ID:
@Id
私人长ID;
尽管我理解在避免云平台上的热点方面需要分散的ID,但是Objectify是一种让旧的增量式ID恢复的方法吗?不得不在UI中显示一个十六进制值(比如1DZENH6BSOW),以避免大量生成的64位id不会削减它。
我很高兴有一个辅助注释@IdLegacy与@Id一起使用,然后@Id仍然会生成长ID,我可以使用旧ID来显示。
解决方案: 在我的网站里面,我有一段简单的代码,如果代码不存在,它会分配一个ID: 据我所知, Objectify传递App引擎数据存储的零散id行为。 Objectify问题跟踪器的快速检查并未显示任何人尚未提出增量ID请求。向Objectify开发者提交请求。 http://code.google.com/p/objectify-appengine/issues/list Since upgrading to GAE 1.8, I'm getting scattered ids when annotating with @Id in Objectify: 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:
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 这篇关于Objectify上的增量ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
if(getId()== null){
ObjectifyFactory f = new ObjectifyFactory();
钥匙< MyEntity> key = f.allocateId(MyEntity.class);
setId(key.getId());
}
@Id
private Long id;
if (getId() == null){
ObjectifyFactory f = new ObjectifyFactory();
Key<MyEntity> key = f.allocateId(MyEntity.class);
setId(key.getId());
}