0

I have below code to get values from datastore in google app engine.

PersistenceManager pm = JDOUtil.get().getPersistenceManager();
Extent extent = pm.getExtent(LeaderBoard.class, true);

Query q = pm.newQuery(extent);
q.setFilter("game =='"+game+"'");
q.setOrdering("time DESC,createdDate DESC");

List<LeaderBoard> leaderBoard = (List<LeaderBoard>) q.execute();
pm.close();

But when I tried its giving me an strange error I am not familiar with at below line.

List<LeaderBoard> leaderBoard = (List<LeaderBoard>) q.execute();

below is the stacktrace. This works sometime. But its not working now. I am using google app engine and jdo.

ERROR :java.lang.ClassCastException: org.datanucleus.query.evaluator.memory.InMemoryFailure cannot be cast to java.lang.Comparable
stackTrace  :java.lang.ClassCastException: org.datanucleus.query.evaluator.memory.InMemoryFailure cannot be cast to java.lang.Comparable
    at org.datanucleus.query.QueryUtils$3.compare(QueryUtils.java:1317)
    at java.util.Arrays.mergeSort(Arrays.java:1446)
    at java.util.Arrays.legacyMergeSort(Arrays.java:1356)
    at java.util.Arrays.sort(Arrays.java:1345)
    at org.datanucleus.query.QueryUtils.orderCandidates(QueryUtils.java:1288)
    at org.datanucleus.query.evaluator.JavaQueryEvaluator.ordering(JavaQueryEvaluator.java:471)
    at org.datanucleus.query.evaluator.JavaQueryEvaluator.execute(JavaQueryEvaluator.java:220)
    at com.google.appengine.datanucleus.query.JDOQLQuery.performExecute(JDOQLQuery.java:153)
    at org.datanucleus.store.query.Query.executeQuery(Query.java:1789)
    at org.datanucleus.store.query.Query.executeWithArray(Query.java:1666)
    at org.datanucleus.store.query.Query.execute(Query.java:1639)
    at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:221)
    at com.googlecreativelab.dao.LeaderBoardDAO.isTopScore(LeaderBoardDAO.java:68)
    at com.googlecreativelab.dao.LeaderBoardDAO.saveTopScore(LeaderBoardDAO.java:26)
    at com.googlecreativelab.service.GameDataService.processRequest(GameDataService.java:188)
    at com.googlecreativelab.service.GameDataService.doGet(GameDataService.java:290)
    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.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:102)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
    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 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.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:266)
    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 com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:447)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:454)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:461)
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:703)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:338)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:330)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:458)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:679)

Below is the Leaderboard class

@PersistenceCapable
public class LeaderBoard implements Serializable {

    private static final long serialVersionUID = 3671283388721366564L;
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent
    private String name;
    @Persistent
    private Integer avatar;
    @Persistent
    private String game;
    @Persistent
    private Integer time;
    @Persistent
    private Date scoredDate;

    //Setter and getters

And also I found that error coming only when there is same value in 'time' column and I am trying to order them by 'order by' query. For example in datastore I have two rows with 955 value for 'time' column. Then I cant do order by, If its 955, 966 something like that order query works. Hope I made this clear :). Is this a bug or something. the value I am passing to game is "run"

2 Answers2

0

So you've enabled querying in-memory, and it can't evaluate all of the query in the datastore and the capabilities of the in-memory evaluator you're using doesn't cater with that query. Presumably using v2.0.x of the GAE JDO plugin (would be nice to actually quote the versions of the software used).

Use v2.1.1 of the GAE JDO plugin (with DataNucleus 3.1.x) which has more complete in-memory querying capabilities.

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
  • I havent enabled querying in memory. I dont know how to do that. And also how to change api packages for gae ? – user1774252 Nov 15 '12 at 09:35
  • Ahh, ok, forgot it defaults to in-memory when it finds something not evaluatable in datastore unless the user says no. The current GAE SDK (1.7.3?) has v2.1.x of the JDO plugin - upgrade the SDK perhaps? – DataNucleus Nov 15 '12 at 10:00
  • ok, I will try to upgrade. Will let you know the progress. But dont you think this is a bug. Please see my edited question – user1774252 Nov 15 '12 at 10:32
  • I have upgraded it, but still error is coming. Versions I am using is GAE 1.7.3, JDO api 3.0.1, datanucleus 3.1.1 – user1774252 Nov 15 '12 at 10:56
  • fixed the issue :), the problem was in the entity I have 'scoredDate' and I am trying to order by 'createdDate'. school boy problem :). But still GAE doesnt give proper exceptions. very bad – user1774252 Nov 15 '12 at 11:25
0

fixed the issue :), the problem was in the entity I have 'scoredDate' and I am trying to order by 'createdDate'. school boy problem :). But still GAE doesnt give proper exceptions. very bad

  • its easy to complain about error messages not telling you what *you* did wrong, but then there are so many things a user can do wrong, and its often impractical to detect all. Obviously you could easily generate a testcase that demonstrates that situation and raise an issue on Googles issues tracker at http://code.google.com/p/datanucleus-appengine/ – DataNucleus Nov 15 '12 at 14:26
  • yeah, as a programmer I understand that. – user1774252 Nov 15 '12 at 16:11