我有下面的代码从谷歌应用引擎的数据存储中获取值。
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();
但是当我尝试它给我一个奇怪的错误时,我在下一行不熟悉。
List<LeaderBoard> leaderBoard = (List<LeaderBoard>) q.execute();
下面是堆栈跟踪。这有时会起作用。但它现在不工作。我正在使用谷歌应用引擎和 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)
下面是排行榜类
@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
而且我发现只有在“时间”列中存在相同值并且我试图通过“排序依据”查询对它们进行排序时才会出现错误。例如,在数据存储中,我有两行,“时间”列的值为 955。然后我不能按顺序进行,如果它的 955、966 类似于该订单查询有效。希望我说清楚了:)。这是一个错误还是什么。我传递给游戏的价值是“运行”