Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have upgraded my GAE server application with the latest GAE SDK 1.9.17 and it stopped work. I am facing a problem while performing 'entityManager.find(Profile.class, 'some long value representing profile id')'.

Here is a stack trace:

java.lang.ClassCastException: com.google.appengine.api.datastore.Key cannot be cast to java.lang.Integer at org.datanucleus.store.appengine.DatastoreFieldManager.fetchIntField(DatastoreFieldManager.java:435) at org.datanucleus.state.AbstractStateManager.replacingIntField(AbstractStateManager.java:1132) at xxx.Profile.jdoReplaceField(Profile.java) at xxx.Profile.jdoReplaceFields(Profile.java) at org.datanucleus.state.JDOStateManagerImpl.replaceFields(JDOStateManagerImpl.java:2772) at org.datanucleus.state.JDOStateManagerImpl.replaceFields(JDOStateManagerImpl.java:2791) at org.datanucleus.store.appengine.DatastorePersistenceHandler.fetchObject(DatastorePersistenceHandler.java:519) at org.datanucleus.state.JDOStateManagerImpl.validate(JDOStateManagerImpl.java:4263) at org.datanucleus.ObjectManagerImpl.findObject(ObjectManagerImpl.java:2444) at org.datanucleus.jpa.EntityManagerImpl.find(EntityManagerImpl.java:234) at org.datanucleus.store.appengine.jpa.DatastoreEntityManager.find(DatastoreEntityManager.java:56) at xxx.GameAdd$1.run(GameAdd.java:34) at xxx.GameAdd$1.run(GameAdd.java:29) at xxx.Action.execute(Action.java:112) at xxx.GameAdd.doPost(GameAdd.java:28) 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 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:254) 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:484) at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:438) at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:445) at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220) at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:309) at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:301) at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:442) at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251) at java.lang.Thread.run(Thread.java:724)

The entity I find is look like:

@Entity public class Profile { public Key getKey() {return key;}

// Other public methods

@Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Key key;

// Other data fields }

The problem started right after I've upgraded the GAE SDK. Code wasn't changed. I always did searches using 'long' values that represent profile id.

I tried to use 'KeyFactory.createKey()' method to generate a key for 'find' method but it didn't help either.

Example:

Key key = KeyFactory.createKey(Profile.class.getSimpleName(), 12345);

Profile p = entitymanager.find(Profile.class, key);

I would appreciate any advises since my server application is unavailable and can't serve end users.

Thanks in advance!

share|improve this question
1  
Which line of code causes this error? –  Andrei Volgin Dec 21 '14 at 18:39
    
ferp.center.server.servlet.GameAdd$1.run(GameAdd.java:34) This line executes: entityManager.find(Profile.class, 12345) –  Oleg Sternberg Dec 21 '14 at 21:05
    
This line Profile p = entitymanager.find(Profile.class, key); cannot give you the same error. What do you mean by "did not help either"? –  Andrei Volgin Dec 21 '14 at 21:11
    
Unfortunately the same effect. I see exactly the same exception. Actually, it was just an example '12345'. In the code I pass to the 'createKey' method a long variable. I verified it a few times. Here the exact code lines: Profile p = em.find(Profile.class, KeyFactory.createKey(Profile.class.getSimpleName(), input.profile)); Where input object is: public class RequestGameResult { public long profile; //... other data fields } –  Oleg Sternberg Dec 22 '14 at 0:32
    
I use IntelliJ Ultimate 14.0.2 which never did any problem, but maybe you'll find this information useful. –  Oleg Sternberg Dec 22 '14 at 0:42

2 Answers 2

up vote 0 down vote accepted

There is a chance of a problem in your build environment, especially if you have just upgraded to the new version and everything did work before. Try to use another tool to build the application, e.g. ant. You can find directions here. It is fairly easy and quick to make it work and it should give you an indication whether the problem is indeed in the new IntelliJ GAE support.

share|improve this answer
    
Many thanks - you saved my day! These instructions indeed resolved my problem and I was managed to upload new version of my server to GAE using 'ant'. Obviously there is a problem with IntelliJ 14.0.2. Hopefully JetBrain will fix it in next release. –  Oleg Sternberg Dec 25 '14 at 7:20

Key key = KeyFactory.createKey(Profile.class.getSimpleName(), 12345);

12345 is considered an Int...

Try this:

long longVal = 12345;

Key key = KeyFactory.createKey(Profile.class.getSimpleName(), longVal);

===---===

Let me know if that helps you.

share|improve this answer
    
Unfortunately the same effect. I see exactly the same exception. Actually, it was just an example '12345'. In the code I pass to the 'createKey' method a long variable. I verified it a few times. Here the exact code lines: Profile p = em.find(Profile.class, KeyFactory.createKey(Profile.class.getSimpleName(), input.profile)); Where input object is: public class RequestGameResult { public long profile; //... other data fields } I use IntelliJ Ultimate 14.0.2 which never did any problem, but maybe you'll find this information useful. –  Oleg Sternberg Dec 22 '14 at 0:40
    
I noticed that I receive another error when I try to persist a Profile entity object: java.lang.IllegalArgumentException: out of field index :9 at xxx.Profile.jdoCopyField(Profile.java) at xxx.Profile.jdoCopyFields(Profile.java) ... I think there is a connection between two problems. Could it be related some how to JPA entity enhancement process? –  Oleg Sternberg Dec 22 '14 at 16:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.