문제

나는 비슷한 질문을 본다 Google App Engine (Java)에서 사전 고급 객체를 저장하는 동안 문제, 그리고 실제로 나는 지속성 관리자에게 Close ()에게 전화하지 않았습니다. 그러나 지금은 가까이에 전화를 걸고 있지만 객체 업데이트는 지속되지 않습니다. 구체적으로, 세트에서 요소를 제거하고 더 작은 세트를 저장하려고합니다. 다음은 Persistence Manager 관련 코드입니다. 예외는 없지만 내 데이터를 저장하지는 않습니다.

    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 Enhancer는 다른 객체 유형 I에 대해 이것을 말해주었습니다. 내 accountInfo 객체에 대해 왜이 경고를 건너 뛰었는지 잘 모르겠습니다.

키를 문자열로 바꾸고 문자열을 올바르게 사용하도록 주석을 변경하여 이제 컬렉션에서 삭제할 수 있습니다.

다른 팁

아무것도 디버깅 할 때 가장 먼저해야 할 일은 로그 (디버그 레벨)를 보는 것입니다. 그것은 다른 지점에있는 객체의 상태를 알려줍니다. 그렇다면 MakePersistent ()라고 부를 때 어떤 상태가 있습니까? 그리고 후? 그리고 pm.close ()를 호출 할 때 어떻게됩니까?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top