我试图在 JDO 中持久化 Hashmap 数据。
最初我创建了一个像
Map<Integer,String> dat=new HashMap<Integer,String>();
这工作得很好,我能够保存数据。但是当我尝试
Map<Integer, ArrayList<String>> dat=new HashMap<Integer,ArrayList<String>>();
我收到类似以下数据的错误:java.util.ArrayList 不是受支持的属性类型。
我使用的是不受支持的数据类型吗?有没有更好的选择??我只是为了学习目的而这样做......所以你的想法会很有帮助..ty
完整代码
servlet.java
public class JdocheckServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
Map<Integer, ArrayList<String>> dat=new HashMap<Integer,ArrayList<String>>();
ArrayList<String> s=new ArrayList<String>();
ArrayList<String> s2=new ArrayList<String>();
s.add("abc");
s.add("abc2");
s.add("abc3");
s2.add("ab4c");
s2.add("ab4c2");
s2.add("ab4c3");
dat.put(23, s);
dat.put(25, s2);
System.out.println(dat);
data d=new data();
PersistenceManager pm=PMF.get().getPersistenceManager();
d.setData(dat);
pm.makePersistent(d);
}}
数据.java
@PersistenceCapable
public class data {
@Persistent
private Map<Integer, ArrayList<String>> data;
public Map<Integer, ArrayList<String>> getData() {
return data;
}
public void setData(Map<Integer, ArrayList<String>> dat) {
this.data = dat;
}
}
访问 servlet 时抛出的错误
HTTP ERROR 500
Problem accessing /jdocheck. Reason:
data: java.util.ArrayList is not a supported property type.
Caused by:
java.lang.IllegalArgumentException: data: java.util.ArrayList is not a supported property type.
at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedSingleValue(DataTypeUtils.java:186)
at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:151)
at com.google.appengine.api.datastore.DataTypeUtils.checkSupportedValue(DataTypeUtils.java:125)
at com.google.appengine.api.datastore.PropertyContainer.setProperty(PropertyContainer.java:102)
at com.google.appengine.datanucleus.EntityUtils.setEntityProperty(EntityUtils.java:172)
at com.google.appengine.datanucleus.StoreFieldManager.storeFieldInEntity(StoreFieldManager.java:360)
at com.google.appengine.datanucleus.StoreFieldManager.storeObjectField(StoreFieldManager.java:186)
at org.datanucleus.state.AbstractStateManager.providedObjectField(AbstractStateManager.java:1447)
at jc.data.jdoProvideField(data.java)
at jc.data.jdoProvideFields(data.java)
at org.datanucleus.state.AbstractStateManager.provideFields(AbstractStateManager.java:1515)
at com.google.appengine.datanucleus.DatastorePersistenceHandler.insertObjectsInternal(DatastorePersistenceHandler.java:242)
at com.google.appengine.datanucleus.BatchPutManager.processBatchState(BatchPutManager.java:34)
at com.google.appengine.datanucleus.BatchManager.finish(BatchManager.java:54)
at com.google.appengine.datanucleus.DatastorePersistenceHandler.batchEnd(DatastorePersistenceHandler.java:194)
at org.datanucleus.ObjectManagerImpl.persistObjects(ObjectManagerImpl.java:1723)
at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistentAll(JDOPersistenceManager.java:779)
at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistentAll(JDOPersistenceManager.java:764)
at jc.JdocheckServlet.doGet(JdocheckServlet.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:60)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:370)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)