我想用Objectify v4获取App Engine中的实体,但它不起作用。谷歌Objectify v4获取ID
- 我@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似乎并没有工作。 问题在哪里?
这在测试用例中正常工作。你确定没有更多的东西没有展示给我们,比如实体中的@Parent字段? – stickfigure
@stickfigure YES,true,我在** **实体**中有一个** Parent **字段。它有什么变化? \ @Parent private Key partOfSpeechEntryKey; –
请仔细阅读,特别是关于Keys的部分:https://code.google.com/p/objectify-appengine/wiki/Concepts – stickfigure