您是否可以在App Engine上的嵌入式类中存储HashMap? 我有以下课程:
@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>();
}
}
但是,当我尝试将一个项目添加到HashMap并持久化时,我收到以下错误:
指定的班级com.google.appengine.api.datastore.Blob不可保留
我知道你可以在“普通”类中成功使用HashMap但是它们是否也可以在嵌入式类中使用?
由于
答案 0 :(得分:0)
我没有尝试使用Embedded类,但我在JDO对象中的Maps需要在包含的类上添加额外的FetchGroup注释...
@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>();
我们必须在打开DataManager时用getFetchPlan()添加这个类......
@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");