【问题标题】:Google App Engine Datastore how to get entity for Key<?>Google App Engine Datastore 如何获取 Key<?> 的实体
【发布时间】:2015-08-13 14:27:51
【问题描述】:

我是 Datastore 的新手,现在我正在使用 Datastore 和 Objectify 开发 Gae 应用程序。实体类的形式

@Entity
public class MyClass1 {
  public Key<MyClass2> field1;
  @Id Long id;
  and so on
 }

MyClass2 的格式为

@Entity
public class MyClass2 {
  ....
  @Id public Long id;
  @Index public String field2;
  ....
}

我有 MyClass1 的实体。如何获得 field2 的值? 如果我使用 DatastoreService1.get(myclass1.field1) 我得到 ​​p>

   method get(Key) in the DatstoreService is not applicable for arguments (Key<MyClass2>)

请帮帮我

【问题讨论】:

    标签: google-app-engine google-cloud-datastore objectify


    【解决方案1】:

    您的错误与问题无关,所以我假设您想获得field1 的值,而不是field2

    错误是因为DatastoreServiceget() 方法需要com.google.appengine.api.datastore.Key,但您传递给它的是com.googlecode.objectifyKey&lt;T&gt;,这是一个Objectify 键——它们不是一回事。 Here are the docs.

    我建议您使用Ref&lt;MyClass2&gt;,因为您可以这样做:

    MyClass2 myClass2 = myClass1.field1.get();
    

    (使用您的代码示例)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-25
      • 2015-07-25
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      • 2012-12-27
      • 2013-01-05
      • 1970-01-01
      相关资源
      最近更新 更多