Google App Engineの中の設定から削除しても、永続化されていません
-
16-09-2019 - |
質問
私は<のhref =「https://stackoverflow.com/questions/1372174/problems-while-saving-a-pre-persisted-object-in-google-app-engine-java」で同様の質問を見ます>問題はGoogle App Engineの(Java)のの中に事前に永続オブジェクトを保存し、実際に私は私の永続性マネージャに近い()を呼び出すされませんでした。しかし、私は今、近くに呼び出していますが、私のオブジェクトの更新は永続化されていません。具体的には、私はセットから要素を削除し、その小さなセットを保存します。ここでは、例外をスローしませんが、私のデータを保存していないコードを、関連するパーシスタンス・マネージャーは、次のとおりです。
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
PersistenceManager pm = PMF.get().getPersistenceManager();
UserProfileInfo userProfile = pm.getObjectById(UserProfileInfo.class,user.getUserId());
int presize = userProfile.getAccounts().size();
AccountInfo ai = userProfile.removeAccount(id);
int postsize = userProfile.getAccounts().size();
UserProfileInfo committed = (UserProfileInfo)pm.makePersistent(userProfile);
int postcommitsize = committed.getAccounts().size();
pm.close();
そして、ここでUserProfileInfoクラスの関連する部分はあります:
@PersistenceCapable(identityType = IdentityType.APPLICATION)
class UserProfileInfo {
@Persistent
private Set<AccountInfo> accounts;
public AccountInfo removeAccount(Long id) throws Exception {
Iterator<AccountInfo> it = accounts.iterator();
StringBuilder sb = new StringBuilder();
while(it.hasNext()) {
AccountInfo acctInfo = it.next();
Long acctInfoId = acctInfo.getId();
if(acctInfoId.equals(id)) {
it.remove();
return acctInfo;
}
sb.append(" ");
sb.append(acctInfoId);
}
throw new Exception("Cannot find id " + id + " Tried " + sb.toString());
}
}
解決
答えは、オブジェクトがロング主キーを使用することはできません所有しているように見えますので。 DataNucleusのエンハンサーは、私が追加別のオブジェクトタイプのために私にこれを告げました。それは私のaccountInfoのオブジェクトに対して、この警告をスキップし、なぜ私はわかりません。
私は、文字列への上で、私の鍵を切り替えて、適切に文字列を使用して注釈を変更し、そして今私は、コレクションから削除することができるよ。
他のヒント
私は何をデバッグするときに最初に行うべきことは、ログ(DEBUGレベル)を見てだろうと考えていると思います。これは、オブジェクトが異なる点であるに述べて何を伝えます。だから、あなたが呼び出すときにてmakePersistent()をどのような状態ですか?以降 ?そして何が起こるあなたがpm.close()を呼び出すとき...