Can you please post your model object definitions for Employee and Department?
Thanks, Max On Mon, Feb 15, 2010 at 11:53 PM, sushama <sush.khadil...@gmail.com> wrote: > import java.util.List; > > import javax.jdo.JDOHelper; > import javax.jdo.PersistenceManager; > import javax.jdo.PersistenceManagerFactory; > import javax.jdo.Transaction; > import javax.persistence.EntityManager; > import javax.persistence.EntityManagerFactory; > import javax.persistence.EntityTransaction; > import javax.persistence.Persistence; > import javax.persistence.Query; > > import com.google.gwt.user.client.Window; > import com.google.gwt.user.server.rpc.RemoteServiceServlet; > import com.wissen.enterprisebysush.client.GreetingService; > import com.wissen.enterprisebysush.server.domainobject.Department; > import com.wissen.enterprisebysush.server.domainobject.Employee; > > /** > * The server side implementation of the RPC service. > */ > @SuppressWarnings("serial") > public class GreetingServiceImpl extends RemoteServiceServlet > implements GreetingService { > > EntityManagerFactory emf = > Persistence.createEntityManagerFactory("transactions-optional"); > > public String greetServer(String input) { > String serverInfo = getServletContext().getServerInfo(); > String userAgent = getThreadLocalRequest().getHeader("User- > Agent"); > return "Hello, " + input + "!<br><br>I am running " + > serverInfo + ".<br><br>It looks like you are using:<br>" + userAgent; > } > > @SuppressWarnings("unchecked") > public void addDept(String dept_name, String dept_head) { > > EntityManager em = null; > > try { > em = emf.createEntityManager(); > em.getTransaction().begin(); > Department d = new Department(); > d.setDept_name(dept_name); > d.setHead(dept_head); > > Query q = em.createQuery("select from > com.wissen.enterprisebysush.server.domainobject.Department d"); > List<Department> deptList = q.getResultList(); > > for (Department dept : deptList) { > System.out.println("Department name: " + > dept.getDept_name()); > } > > em.persist(d); > > } finally { > em.getTransaction().commit(); > em.close(); > > } > > } > > public void addEmp(String emp_name, String emp_sal, String did) { > EntityManager em = emf.createEntityManager(); > try { > > > String s = did; > > EntityTransaction transaction = em.getTransaction(); > transaction.begin(); > System.out.println("value of Department_name is::" + s); > System.out.println("Transaction is active and > is::"+transaction); > > // Query q = em.createQuery("select dept_id > from com.wissen.enterprisebysush.server.domainobject.Department d > where d.dept_name = ?1"); > // q.setParameter(1, s); > // System.out.println("Name of Department is::" > + s); > // Department dept = (Department) > q.getSingleResult(); > > Query q = em.createQuery("select from > com.wissen.enterprisebysush.server.domainobject.Department d"); > Department dept = (Department) q.getResultList().get(0); > System.out.println("Name of Department is::" + > dept.getDept_name()); > > //System.out.println("Query executed > Successfully!!!!!!!!!!!!!!" + q.getSingleResult()); > Employee e = new Employee(); > e.setEmp_name("Abdch"); > e.setEmp_sal("5000"); > e.setDepartment(dept); > em.persist(e); > > System.out.println("Transaction: " + transaction); > > transaction.commit(); > em.close(); > > } catch (NullPointerException e) { > e.printStackTrace(); > System.out.println("Exception::" + e.getCause()); > } finally { > > } > } > > } > > output:: > > > value of Department_name is::Production > Transaction is active and > is::org.datanucleus.jpa.entitytransactioni...@1a21c7d > Name of Department is::Accounts > Transaction: org.datanucleus.jpa.entitytransactioni...@1a21c7d > java.lang.NullPointerException > Exception::null at > com.google.appengine.api.datastore.KeyFactory.stringToKey(KeyFactory.java: > 181) > at > > org.datanucleus.store.appengine.DatastoreElementContainerStoreSpecialization.extractElementKey(DatastoreElementContainerStoreSpecialization.java: > 170) > at > > org.datanucleus.store.appengine.DatastoreAbstractCollectionStoreSpecialization.contains(DatastoreAbstractCollectionStoreSpecialization.java: > 57) > at > > org.datanucleus.store.mapped.scostore.AbstractCollectionStore.contains(AbstractCollectionStore.java: > 116) > at org.datanucleus.sco.backed.List.contains(List.java:455) > at > > org.datanucleus.state.RelationshipManager.processManyToOneBidirectionalRelation(RelationshipManager.java: > 690) > at > org.datanucleus.state.RelationshipManager.process(RelationshipManager.java: > 294) > at > > org.datanucleus.state.JDOStateManagerImpl.processManagedRelations(JDOStateManagerImpl.java: > 2377) > at > > org.datanucleus.ObjectManagerImpl.performManagedRelationships(ObjectManagerImpl.java: > 2706) > at org.datanucleus.ObjectManagerImpl.flush(ObjectManagerImpl.java: > 2744) > at > org.datanucleus.ObjectManagerImpl.preCommit(ObjectManagerImpl.java: > 2886) > at > org.datanucleus.TransactionImpl.internalPreCommit(TransactionImpl.java: > 348) > at org.datanucleus.TransactionImpl.commit(TransactionImpl.java:235) > at > > org.datanucleus.jpa.EntityTransactionImpl.commit(EntityTransactionImpl.java: > 104) > at > > com.wissen.enterprisebysush.server.GreetingServiceImpl.addEmp(GreetingServiceImpl.java: > 94) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: > 39) > at > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: > 25) > at java.lang.reflect.Method.invoke(Method.java:597) > at > com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java: > 527) > at > > com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java: > 166) > at > > com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java: > 86) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:713) > 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.content(HttpConnection.java:844) > at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644) > 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) > > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine for Java" group. > To post to this group, send email to > google-appengine-j...@googlegroups.com. > To unsubscribe from this group, send email to > google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/google-appengine-java?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-j...@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.