Google app engine Key.create vs.ofy().load()

Google app engine Key.create vs.ofy().load(),google-app-engine,objectify,Google App Engine,Objectify,我想得到一个实体的密钥(我不需要实际的实体。我需要密钥只是为了得到一个子实体) 所以我知道有两种方法: // 1. Key<Thing> tKey = com.googlecode.objectify.Key.create(Thing.class, id); // 2. Key<Thing> tKey = ofy().load().type(Thing.class).id(id); 您想使用键。创建(东西,id) ofy().load().type(Thing.cla

我想得到一个实体的密钥(我不需要实际的实体。我需要密钥只是为了得到一个子实体)

所以我知道有两种方法:

// 1.
Key<Thing> tKey = com.googlecode.objectify.Key.create(Thing.class, id);

// 2.
Key<Thing> tKey = ofy().load().type(Thing.class).id(id);

您想使用
键。创建(东西,id)

ofy().load().type(Thing.class).id(id)
返回一个
Ref
,而不是
键。它实际上是从数据存储中加载内容,这不是您想要的

Thing t = tKey.get();