I followed the following thread (http://groups.google.com/group/google-
appengine-java/browse_thread/thread/fb12ab60c68bf664/400cf3c83be90ce9?
lnk=gst&q=persist+hashmap)  to successfully persist my hashmap. I had
a hard time to get it working because of the following issue:

If I use the following method to retrieve my object:
  @Override
  public T get(Class<T> c, K id) {

//    PersistenceManager pm = getPersistenceManager();
          PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
      T result = pm.detachCopy(pm.getObjectById(c, id));
      return result;
    } catch (JDOObjectNotFoundException e) {
      return null;
    }
    finally {
      releasePersistenceManager(pm);
    }
  }

everything works fine.

If I omit the detachcopy(), I can retrieve the object but the hashmap
is always null.
  @Override
  public T get(Class<T> c, K id) {

//    PersistenceManager pm = getPersistenceManager();
          PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
      T result = pm.getObjectById(c, id);
      return result;
    } catch (JDOObjectNotFoundException e) {
      return null;
    }
    finally {
      releasePersistenceManager(pm);
    }
  }



For instance in the class below,  once the StateCore has been saved, I
could retrieve the ID but the users hashmap would be null wiithout the
detachcopy().

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class StateCore implements Serializable {
  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private Key key;
  @Persistent(serialized = "true")
  private HashMap<String, CustomUser> users;
  public Long getId() {
    return key.getId();
  }
....

Could someone kindly explain why it's behaving that way?

Thanks in advance

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.


Reply via email to