title: Why am I getting a cast error in my Query using JDO on Google App Engine?
body: <p>According to <a href="http://code.google.com/intl/pl/appengine/docs/java/datastore/queriesandindexes.html#Introducing_Queries" rel="noreferrer">the Queries and Indexes doc</a> you can go a query effectively identically (so far as I can tell) to this:</p>
  
  <pre><code>PersistenceManager pm = PMF.get().getPersistenceManager();
  try {
      Query q = pm.newQuery(App.class);
      q.setOrdering("name desc");
  
      try {
          results = (ArrayList&lt;App&gt;) q.execute();
      } finally {
          q.closeAll();
      }
  } finally {
      pm.close();
  }
  </code></pre>
  
  <p>However, I'm getting the following error on the <code>results = (ArrayList&lt;App&gt;) q.execute();
  </code> line:</p>
  
  <pre><code>java.lang.ClassCastException: org.datanucleus.store.appengine.query.StreamingQueryResult cannot be cast to java.util.ArrayList
      at com.killerrobots.AppSite.MainServlet.getApplications(MainServlet.java:66)
      at com.killerrobots.AppSite.MainServlet.doGet(MainServlet.java:26)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
      at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
      at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
      at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
      at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
      at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
      at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:306)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
      at org.mortbay.jetty.Server.handle(Server.java:313)
      at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
      at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830)
      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
      at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
      at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
      at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
  </code></pre>
  
  <p>Any ideas?</p>