aspose file tools*
The moose likes Object Relational Mapping and the fly likes JPA select query using Google App engine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA select query using Google App engine" Watch "JPA select query using Google App engine" New topic
Author

JPA select query using Google App engine

Praveen Sangolli
Greenhorn

Joined: May 22, 2008
Posts: 28
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

Joined: Aug 17, 2008
Posts: 115
Is Employee class exist in same package ?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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

Joined: May 22, 2008
Posts: 28
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

Joined: May 22, 2008
Posts: 28
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




 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA select query using Google App engine