[英]How do I get a Datastore Entity by its unique ID if I know the ID?
這就是我創建實體的方式
Key reviewsKey = KeyFactory.createKey("Reviews", "Reviews");
Entity reviewEntity = new Entity("aReview", reviewsKey);
....
這就是我試圖通過其鍵獲取實體的方式
Key key = KeyFactory.createKey("Reviews", "Reviews");
Entity reviewEntity = datastore.get(key.getChild("aReview", reviewId));
....
我知道有一個鍵= 14的實體,但我不斷收到一個例外,即找不到任何實體
評論(“評論”)/ aReview(“ 14”)
我究竟做錯了什么?
問題是當它應該為Long時正在尋找一個字符串ID
我已經將其解析為Long,並且現在可以使用了。
Key key = KeyFactory.createKey("Reviews", "Reviews");
Entity reviewEntity = datastore.get(key.getChild("aReview", Long.parseLong(reviewId)));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.