代码之家  ›  专栏  ›  技术社区  ›  Michael Donohue Reno

从Google App Engine中的集合中删除不会被持久化

  •  1
  • Michael Donohue Reno  · 技术社区  · 16 年前

    我看到一个类似的问题 Problems while saving a pre-persisted object in 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();
    

    @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());
      }
    }
    
    2 回复  |  直到 8 年前
        1
  •  1
  •   Michael Donohue Reno    16 年前

    因此,答案似乎是拥有对象不能使用Long主键。datanucleus增强器告诉我,这是我添加的另一种物体类型。我不知道为什么它跳过了我的AccountInfo对象的此警告。

        2
  •  0
  •   DataNucleus    16 年前