【发布时间】:2014-10-21 13:01:49
【问题描述】:
我有一个 ID 字段为字符串的数据存储类型
ofy().load().type( Scores.class ).id( playerName ).now();
这会获取 null。我已确认具有给定玩家名称的实体存在。 这不会发生在另一个 ID 很长的 Kind 上。
分数类代码
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Parent;
@Entity
public class Scores
{
@Parent
public Key<RankerRoot> parentKey;
@Id
public String playerName;
public int value;
}
【问题讨论】:
-
你能给出你的Scores Class的代码吗?目前你可以尝试做
plarName.trim()。一年前,我在一个应用程序中遇到了字符串格式的问题。 -
您是否还可以看到键名为
playerName的实体存在于数据存储中(使用数据存储查看器)并且它没有祖先? -
@tx802 加油!它有一个祖先。我应该看到它的到来。让我尝试在语句中添加祖先()。
-
@Pintouch 用代码更新问题。
-
您可以使用
Key<Scores> key = Key.create(parentKey, Scores.class, playerName)单独创建密钥,然后调用ofy().load().key(key).now()- 可以吗?
标签: google-app-engine google-cloud-datastore objectify