4

Objectifyv4を使用してAppEngineでエンティティをフェッチしようとしていますが、機能しません。

  • 私の@Entity:Translation.class
  • フェッチしたい@Entityの@Id:301L

私の@Entity:

@Entity
public class Translation {
  @Id
  private Long id;
  private String text;

  public String getText() {
    return text;
  }

  public Long getId() {
    return id;
  }

  public void setText(String text) {
    this.text = text;
  }
}

言葉ではないリクエスト:

Translation translation =ObjectifyService.ofy().load().type(Translation.class).id(301L).get(); // translation is null

しかし、私がそうする場合:

 Translation translation = ObjectifyService.ofy().load().type(Translation.class).first().get(); // translation is not null

それで:

System.out.println(translation.getId()); // translation id equal 301

したがって、idによるフェッチは機能していないようです。問題はどこだ?

4

2 に答える 2

5

エンティティには@Parentフィールドがあるため、IDで取得するには、次のコマンドを実行する必要があります。

Translation translation = ObjectifyService.ofy().load().type(Thing.class).parent(par).id(301).get();

詳細については、 Objectifyの基本操作-読み込みをご覧ください。

お役に立てれば!

于 2012-11-08T11:36:10.323 に答える
0

@stickfigureの場合、これは私の実際の@Entityです(PartOfSpeechGroupは明らかに@Entityでもあります)。

@Entity
public class Translation implements IsSerializable {
  @Id
  private Long id;
  private String text;
  @Parent
  private Key<PartOfSpeechGroup> partOfSpeechEntryKey;

  public Translation() {}

  public Translation(Key<PartOfSpeechGroup> partOfSpeechEntryKey) {
    this.partOfSpeechEntryKey = partOfSpeechEntryKey;
  }

  public String getText() {
    return text;
  }

  public Long getId() {
    return id;
  }

  public Key<PartOfSpeechGroup> getPartOfSpeechEntryKey() {
    return partOfSpeechEntryKey;
  }

  public void setText(String text) {
    this.text = text;
  }
}
于 2012-11-09T02:23:17.820 に答える