我正在开发一个Google App Engine托管后端数据存储区的项目,我可以发送JSON请求通过我的网站点击它。
我有多个表(IE订单信息,优惠券等),只是创建了一个新表Session。我的想法是,我希望数据库存储会话ID,而不是使用Memcache来保存数据。我编写了代码来检查它,但每当我在数据库中搜索会话ID时,它都会返回一个错误:
org.datanucleus.api.jdo.NucleusJDOHelper getJDOExceptionForNucleusException: Exception thrown
Received a request to find an object of kind Session but the provided identifier is the String representation of a Key for kind Token
我对此感到困惑的问题是为什么这会成为一个问题,当我使用String作为主键对数据库执行的其他查询工作正常...任何人有任何想法?
完整错误输出:
org.datanucleus.api.jdo.NucleusJDOHelper getJDOExceptionForNucleusException: Exception thrown
Received a request to find an object of kind Session but the provided identifier is the String representation of a Key for kind Token
org.datanucleus.exceptions.NucleusFatalUserException: Received a request to find an object of kind Session but the provided identifier is the String representation of a Key for kind Token
at com.google.appengine.datanucleus.EntityUtils.stringToInternalKey(EntityUtils.java:423)
at com.google.appengine.datanucleus.EntityUtils.idToInternalKey(EntityUtils.java:218)
at com.google.appengine.datanucleus.EntityUtils.idToInternalKey(EntityUtils.java:208)
at com.google.appengine.datanucleus.DatastoreIdentityKeyTranslator.getKey(DatastoreIdentityKeyTranslator.java:32)
at org.datanucleus.ObjectManagerImpl.newObjectId(ObjectManagerImpl.java:3443)
at org.datanucleus.api.jdo.JDOPersistenceManager.newObjectIdInstance(JDOPersistenceManager.java:1618)
at org.datanucleus.api.jdo.JDOPersistenceManager.getObjectById(JDOPersistenceManager.java:1740)
at com.package.core.DataSourceMgr.getObjectById(DataSourceMgr.java:118)
at com.package.service.SessionService.getSession(SessionService.java:39)
at com.package.misc.TESTQueryDBForSessionID.execute(TESTQueryDBForSessionID.java:25)
at com.package.batch.CronShell.doGet(CronShell.java:40)
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.package.core.DataSourceFilter.doFilter(DataSourceFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
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.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.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 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:257)
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:482)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:230)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:234)
at java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:1)
显然,问题是双重的。
首先,系统出现了问题,我使用String作为主键(不知道为什么这个问题是一个问题而其他问题没有问题......)。将其切换为随机生成的长整数。
这解决了第一个问题,但随后又出现了第二个问题,当你有一个GAE数据存储区的主键/ ID时,你无法查询它。您必须使用Long(盒装版本,大写L)而不是很长时间才能工作。之后,能够删除数据存储区中的现有项目并上传新代码。
tl; dr - 如果有人再遇到过这个问题,请确保: 1)您正在使用某种类型的Long作为ID /主键 2)您在代码中使用Long(不长):
public class Session extends BaseEntity {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
//...
}
-Pat