Appengine:查询结果不支持此操作

时间:2013-09-09 15:05:56

标签: google-app-engine google-cloud-endpoints

我已经以这种方式修改了Eclipse生成的默认Google云端点:

@ApiMethod(name = "insertDeviceInfo")
    public DeviceInfo insertDeviceInfo(DeviceInfo deviceinfo) {
        EntityManager mgr = getEntityManager();
        try {
            if (containsDeviceInfo(deviceinfo)) {

                            logger.info("deviceinfo: già presente (insertDeviceinfo)");
                throw new EntityExistsException("Object already exists");

                logger.info("deviceinfo: già presente (insertDeviceinfo)");
            }
            mgr.persist(deviceinfo);
            String iddevice= deviceinfo.getDeviceRegistrationID();
            logger.info("deviceinfo: "+iddevice+" , "+deviceinfo.getDeviceInformation()+" , "+deviceinfo.getLanguage()+" , "+deviceinfo.getTimestamp()+ " , "+deviceinfo.getTimestamplastused());
            ChannelJDOWrapper.idDevice.add(iddevice);
            CacheSupport.cachePut(DeviceInfo.class.getName(), deviceinfo.getDeviceRegistrationID(), deviceinfo);
            logger.info("dispositivo inserito");
        } finally {
            mgr.close();
        }

ChannelJDOWrapper.idDevice是一个静态LinkedList<串GT; ()。

现在有时我收到这个例外:

com.google.api.server.spi.SystemService invokeServiceMethod: This operation is not supported on Query Results
java.lang.UnsupportedOperationException: This operation is not supported on Query Results
    at org.datanucleus.query.evaluator.InMemoryQueryResult.add(InMemoryQueryResult.java:321)
    at com.iuculano.tvitaliane.server.DeviceInfoEndpoint.insertDeviceInfo(DeviceInfoEndpoint.java:163)
    at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:45)
    at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:361)
    at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:124)
    at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:82)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    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 org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    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 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.HttpConnection.handle(HttpConnection.java:404)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:435)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:442)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:186)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:306)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:298)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:439)
    at java.lang.Thread.run(Thread.java:722)

DeviceInfoEndpoint.java:163是:

  

ChannelJDOWrapper.idDevice.add(iddevice);

为什么?

1 个答案:

答案 0 :(得分:1)

如果通过JDO查询加载ChannelJDOWrapper.idDevice,那么它将是JDO提供的List实现 - 从stacktrace判断它是InMemoryQueryResult。它的内容不可修改(参见GAE JDO作者的this answer)。

您需要复制一份清单才能修改它:

ChannelJDOWrapper.idDevice = new LinkedList(ChannelJDOWrapper.idDevice);