JDO - HashMap within an embedded Class

旧时模样 提交于 2019-12-11 07:03:15

问题


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:


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");


来源:https://stackoverflow.com/questions/6117495/jdo-hashmap-within-an-embedded-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!