could not persist data of format map<string,Arraylist> in jdo

一个人想着一个人 提交于 2020-01-06 08:10:31

问题


iam trying to persist a Hashmap data in JDO.

initially i created a Hashmap like

Map<Integer,String> dat=new HashMap<Integer,String>();

and this worked perfectly and i was able to save data., but when i tried

Map<Integer, ArrayList<String>> dat=new HashMap<Integer,ArrayList<String>>();

i got an error like this data: java.util.ArrayList is not a supported property type.

am i using a non supported data type ?? is there a better alternative ?? i am just doing this for learning purpose ...so your ideas will be very helpful ..ty

complete code

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

}}   

data.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;
}
}

error thrown when accessing the 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)

回答1:


Q. In what circumstances did you get your error?... A. During compile time...

To me, it looks like your error happens during run-time.

Am I using a non supported data type?

As @DataNucleus alludes to above, your error trace indicates that the GAE datastore does not support this property type.

Is there a better alternative?

That depends on what you want your code to do.



来源:https://stackoverflow.com/questions/12373389/could-not-persist-data-of-format-mapstring-arraylist-in-jdo

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