[英]GAE Datastore saves an entity then doesn't update it using Java / Objectify
我有一些簡單的代碼可以處理個人資料圖片的上傳(這是BlobstoreService
完成其巫毒之后的回調)。
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
BlobstoreService blobSvc = BlobstoreServiceFactory.getBlobstoreService();
Map<String, List<BlobKey>> blobs = blobSvc.getUploads(req);
List<BlobKey> blobKeys = blobs.get(UserSvc.fieldProfileImg);
String principalKey = req.getParameter(UserSvc.fieldPrincipalKey);
boolean failure = true;
if (null != blobKeys && blobKeys.size() > 0) {
Optional<Principal> princi = GaeDataUtil.getByWebKey(principalKey);
if (princi.isPresent()) {
log.info("Before adding BlobKey: " + princi.get());
princi.get().setProfileImgKey(blobKeys.get(0));
princi.get().setMiddleName("Saved"); // just to test if any other value will update
ofy().save().entity(princi.get()).now();
log.info("After adding BlobKey and saving: " + princi.get());
failure = false;
res.getWriter().print("SUCCESS");
} else {
log.warning("Failed to find Principal with web key: " + principalKey);
}
}
if (failure) {
res.getWriter().print("FAIL");
}
}
一切正常,除了重新保存檢索到的實體。
我自己的服務器端代碼正在將個人資料圖片數據提交到BlobstoreService
(讓我們不去解釋為什么這樣做)。 提交/上傳有效,能夠在devserver的admin / Datastore中看到它,我得到了想要的BlobKey
,甚至可以從webKey
檢索Principal
,但是似乎無法保存更新的實體。 也不例外。
最初,當我嘗試此操作時,我沒有檢索BlobKey
,而是注意到數據存儲區將顯示兩個特殊實體: __BlobInfo__
和我不記得其名稱的另一個實體,但它以__
(雙下划線)開頭和結尾。 刷新內存緩存后,我只能看到__BlobInfo__
實體,而另一個實體無處可見。 我刪除了target\\<appname>-1.0-SNAPSHOT\\WEB-INF\\appengine-generated\\local_db.bin
試圖重置數據存儲,但是我仍然看不到數據存儲中其他特殊實體的任何跡象。
有沒有辦法在開發服務器上重置數據存儲和Blob存儲?
環境:
如果您正在尋找一種方法來僅在開發服務器中重置Blob存儲和數據存儲條目,則可以嘗試在appengine-web.xml
更改應用程序名稱。
<application>appname</application>
如果您在此處提供一個不同的(虛擬)名稱,那么如果您重新運行開發服務器,它將在開發服務器中重置內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.