本文介绍了嵌入式类中的JDO - HashMap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是否可以在App Engine的嵌入式类中存储HashMap?
我有以下类:

pre $ @Persistent(serialized =true)
@Embedded
个人统计数据;

@PersistenceCapable
@EmbeddedOnly
public static class Stats实现Serializable {
private static final long serialVersionUID = 1L;
@Persistent(serialized =true,defaultFetchGroup =true)
私人地图< String,Integer>要求;
$ b public Stats(){
requests = new HashMap< String,Integer>();


但是,当我尝试将项目添加到HashMap并坚持它我得到以下错误:

指定的类类com.google.appengine.api.datastore.Blob不可持久化



我知道你可以在普通类中成功使用HashMap,但是它们也可以用于嵌入类吗?



谢谢

解决方案

我没有用Embedded类试过它,但是我的JDO对象内的Maps需要额外的FetchGroup注解在包含类...

$ p $ @SuppressWarnings(serial


@PersistenceCapable(identityType = IdentityType.APPLICATION,detachable =true)
@FetchGroup(name =QueryAggregationJobJDO,members = {
@Persistent(name =appName,recursionDepth = -1),
等...
public class QueryAggregationJobJDO extends AggregationJobJDO implements SystemObject {
@Persistent(serialized =true)//这是应用程序名称字符串和每个找到的名称的计数
public Map<字符串,长> appName = new HashMap< String,Long>();

我们必须在打开DataManager时使用getFetchPlan()添加此类...

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

pm = PMF.get(type).getPersistenceManager();

if
pm.getFetchPlan()。addGroup(TouchActiveUserJDO);
pm.getFetchPlan()。addGroup(UserRoleJDO);
pm.getFetchPlan()。addGroup(QueryAggregationJobJDO);


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

解决方案

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

这篇关于嵌入式类中的JDO - HashMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 01:22