title: java.lang.Long cannot be cast to java.lang.Integer JPA GAE and enumeration
body: <p>I have a problem with JPA and GAE. When i try to do query on all 'Index_Book's i get <strong>java.lang.Long cannot be cast to java.lang.Integer</strong> exception. Which lead me to this line in the Index class</p>
  
  <pre><code>@Enumerated(EnumType.ORDINAL)
  public Platform platform;
  </code></pre>
  
  <p>I would like to refrain from using the EnumType.STRING because i expect lots of entites and with just 3 different enums. I was thinking of using converters but i don't know what affects does that have on the indexing.</p>
  
  <p>I have Entity which looks like this. DatastoreObject is just an object for some common methods and other stuff.</p>
  
  <pre><code>@Entity
  @MappedSuperclass
  public abstract class Index extends DatastoreObject {
  
      @Id
      private Key ID;
  
      @Extension(vendorName = "datanucleus", key = "gae.parent-pk", value ="true")
      public Key organizationID;
  
      @Enumerated(EnumType.ORDINAL)
      public Platform platform;
  
      ...
  }
  </code></pre>
  
  <p>derived class from Index.</p>
  
  <pre><code>@Entity
  public class Index_Book extends Index {
  
      ...
  }
  </code></pre>
  
  <p>This is where i get java cast exception when i call tq.getResultList()</p>
  
  <pre><code>Query tq =  em.createQuery(String.format("SELECT FROM %s s", "IndexBook"));
  
  
  for(Index si : (List&lt;Index&gt;)tq.getResultList()){
      ...
  }
  </code></pre>
  
  <p>Any idea how to get around this problem?
  The catch is platform must be indexed. So it can also be searched by that.</p>
  
  <p><strong>EDIT:</strong>
  This is full exception:</p>
  
  <pre><code>java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
      at com.google.appengine.datanucleus.TypeConversionUtils.datastoreValueToPojoValue(TypeConversionUtils.java:403)
      at com.google.appengine.datanucleus.FetchFieldManager.fetchFieldFromEntity(FetchFieldManager.java:463)
      at com.google.appengine.datanucleus.FetchFieldManager.fetchObjectField(FetchFieldManager.java:408)
      at org.datanucleus.state.AbstractStateManager.replacingObjectField(AbstractStateManager.java:2353)
      at s4a.projectpinus.backend.shared.db.models.statistics.v2.abst.StatisticsIndex.jdoReplaceField(StatisticsIndex.java)
      at s4a.projectpinus.backend.shared.db.models.statistics.v2.StatisticsIndex_SessionTime.jdoReplaceField(StatisticsIndex_SessionTime.java)
      at s4a.projectpinus.backend.shared.db.models.statistics.v2.abst.StatisticsIndex.jdoReplaceFields(StatisticsIndex.java)
      at org.datanucleus.state.JDOStateManager.replaceFields(JDOStateManager.java:1935)
      at org.datanucleus.state.JDOStateManager.replaceFields(JDOStateManager.java:1962)
      at com.google.appengine.datanucleus.DatastorePersistenceHandler.fetchObject(DatastorePersistenceHandler.java:567)
      at org.datanucleus.state.JDOStateManager.loadFieldsFromDatastore(JDOStateManager.java:1638)
      at org.datanucleus.state.JDOStateManager.loadUnloadedFieldsInFetchPlan(JDOStateManager.java:1363)
      at org.datanucleus.state.JDOStateManager.detach(JDOStateManager.java:2718)
      at org.datanucleus.ObjectManagerImpl.performDetachOnCloseWork(ObjectManagerImpl.java:4571)
      at org.datanucleus.ObjectManagerImpl.performDetachOnClose(ObjectManagerImpl.java:4534)
      at org.datanucleus.ObjectManagerImpl.close(ObjectManagerImpl.java:1105)
      at org.datanucleus.api.jpa.JPAEntityManager.close(JPAEntityManager.java:193)
      at s4a.projectpinus.backend.core.DispatcherServlet.doGet(DispatcherServlet.java:148)
      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.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:127)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
      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 com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
      at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
      at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
      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.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:491)
      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 org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
      at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
      at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
  </code></pre>