Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA select query using Google App engine

 
Praveen Sangolli
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

I have an issue selecting the data from the datastore. Here is the code

EntityManager pm = PMF.get().createEntityManager();
EntityTransaction tx = pm.getTransaction();
Query query = pm.createQuery("SELECT p FROM Employee p ");

List results = query.getResultList();
for (Iterator iterator = results.iterator(); iterator.hasNext();) {
Employee object = (Employee) iterator.next();
System.out.println();
System.out.println("Print "+object.getFirstName());
System.out.println();


}

I am getting this error when i run the code

org.datanucleus.exceptions.ClassNotResolvedException: Employee


Any help is appreciated




 
Kathiresan Chinna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is Employee class exist in same package ?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which development and runtime enviroment are you running?

It looks like perhaps a classpath issue, although in that case you usually get a "ClassNotFoundException" as opposed to it saying something about being resolved.

Where on your classpath is Employee?

-Cameron McKenzie
 
Praveen Sangolli
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thank you for your replies. Yes as you said it it was an issue with the classpath , i had to specify the fully qualified class name of the Employee entity though it was in the same package.

Thanks
 
Praveen Sangolli
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Now that the classpath issue is resolved, the select query and the insert query to the datastore are working fine, but it throws an exception when i try updating the datastore. The update query is


EntityManager pm = PMF.get().createEntityManager();
EntityTransaction tx = pm.getTransaction();

Query query = pm.createQuery("update "+Employee.class.getName()+" set firstName=:Murali");
query.executeUpdate();



And the exception is:



java.lang.ClassCastException: org.datanucleus.store.appengine.query.StreamingQueryResult cannot be cast to java.lang.Long
at org.datanucleus.jpa.JPAQuery.executeUpdate(JPAQuery.java:109)
at guestbook.UpdateServlet.doGet(UpdateServlet.java:44)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:306)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:313)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)



Can anyone tell me why is it casting to a long when the executeUpdate returns an int. And a sample code on how to update the datastore.

Regards
Praveen N Sangolli




 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic