JDO - HashMap within an embedded Class

2019-07-23 20:11发布

Are you able to store a HashMap within an embedded class on App Engine? I have the following Class:

@Persistent(serialized = "true")
@Embedded
private Stats stats;

@PersistenceCapable
@EmbeddedOnly
public static class Stats implements Serializable {
    private static final long serialVersionUID = 1L;        
    @Persistent(serialized = "true", defaultFetchGroup="true")
    private Map<String, Integer> requests;

    public Stats() {
        requests = new HashMap<String, Integer>();
    }
}

However, when I attempt to add an item to the HashMap and persist it I get the following error:

Specified class class com.google.appengine.api.datastore.Blob is not persistable

I know you can successfully use a HashMap in a "normal" class but can they be used in embedded Class's also?

Thanks

1条回答
贪生不怕死
2楼-- · 2019-07-23 20:53

I haven't tried it with an Embedded class, but my Maps inside JDO objects needed additional FetchGroup annotations on the containing class...

    @SuppressWarnings("serial

        ")
        @PersistenceCapable(identityType=IdentityType.APPLICATION, detachable="true")
        @FetchGroup(name="QueryAggregationJobJDO", members={
                                                @Persistent(name="appName", recursionDepth=-1),
etc....                                         
        public class QueryAggregationJobJDO extends AggregationJobJDO implements SystemObject {
            @Persistent(serialized="true")  // this is string of app names and a count for each name found
            public Map< String, Long >  appName = new HashMap<String, Long>();

and we had to add this class with getFetchPlan() when opening our DataManager...

@Override
public boolean open() {
    DataAreaManager dataAreaManager = new DataAreaManager();
    dataAreaManager.setDataArea(VERSION_DATA_AREA);

    if ((pm == null) || (pm.isClosed())) {

        pm = PMF.get(type).getPersistenceManager();
        pm.getFetchPlan().addGroup("TouchActiveUserJDO");
        pm.getFetchPlan().addGroup("UserRoleJDO");
        pm.getFetchPlan().addGroup("QueryAggregationJobJDO");
查看更多
登录 后发表回答