• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JPA select query using Google App engine

 
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




 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is Employee class exist in same package ?
 
author and cow tipper
Posts: 5000
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




 
Could you hold this puppy for a sec? I need to adjust this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic