surinder-insonix / datanucleus-appengine

Automatically exported from code.google.com/p/datanucleus-appengine
0 stars 0 forks source link

NullPointer if I try to access an object which has a join #317

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
If I have an object:

Contact with a field List<ContactMethod> listofContactMethods, when I run a 
query:

select Contact where id = x I get a list of Contact objects back and when I try 
to access any of them beyond checking for null I get:

com.adaptavant.distributedsource.dao.ContactDAO getContactByOwner: null
java.lang.NullPointerException
    at com.google.appengine.api.datastore.AsyncDatastoreServiceImpl$EntityGroupGrouper.getEntityGroupKey(AsyncDatastoreServiceImpl.java:168)
    at com.google.appengine.api.datastore.AsyncDatastoreServiceImpl$2.extractEntityGroupKey(AsyncDatastoreServiceImpl.java:197)
    at com.google.appengine.api.datastore.AsyncDatastoreServiceImpl$2.extractEntityGroupKey(AsyncDatastoreServiceImpl.java:194)
    at com.google.appengine.api.datastore.AsyncDatastoreServiceImpl$EntityGroupGrouper.getItemsByEntityGroup(AsyncDatastoreServiceImpl.java:155)
    at com.google.appengine.api.datastore.AsyncDatastoreServiceImpl.get(AsyncDatastoreServiceImpl.java:276)
    at com.google.appengine.api.datastore.DatastoreServiceImpl$1.runInternal(DatastoreServiceImpl.java:68)
    at com.google.appengine.api.datastore.DatastoreServiceImpl$1.runInternal(DatastoreServiceImpl.java:65)
    at com.google.appengine.api.datastore.TransactionRunner.runInTransaction(TransactionRunner.java:29)
    at com.google.appengine.api.datastore.DatastoreServiceImpl.get(DatastoreServiceImpl.java:65)
    at com.google.appengine.datanucleus.WrappedDatastoreService.get(WrappedDatastoreService.java:80)
    at com.google.appengine.datanucleus.FetchFieldManager.getCollectionFromDatastoreObject(FetchFieldManager.java:666)
    at com.google.appengine.datanucleus.FetchFieldManager.fetchRelationField(FetchFieldManager.java:483)
    at com.google.appengine.datanucleus.FetchFieldManager.fetchObjectField(FetchFieldManager.java:405)
    at org.datanucleus.state.AbstractStateManager.replacingObjectField(AbstractStateManager.java:2353)
    at com.adaptavant.distributedsource.objects.Contact.jdoReplaceField(Contact.java)
    at com.adaptavant.distributedsource.objects.Contact.jdoReplaceFields(Contact.java)
    at org.datanucleus.state.JDOStateManager.replaceFields(JDOStateManager.java:1935)
    at org.datanucleus.state.JDOStateManager.replaceFields(JDOStateManager.java:1962)
    at com.google.appengine.datanucleus.EntityUtils$1.fetchFields(EntityUtils.java:974)
    at org.datanucleus.state.JDOStateManager.loadFieldValues(JDOStateManager.java:764)
    at org.datanucleus.state.JDOStateManager.initialiseForHollow(JDOStateManager.java:205)
    at org.datanucleus.state.StateManagerFactory.newForHollowPopulated(StateManagerFactory.java:89)
    at org.datanucleus.state.ObjectProviderFactory.newForHollowPopulated(ObjectProviderFactory.java:75)
    at org.datanucleus.ObjectManagerImpl.findObject(ObjectManagerImpl.java:2882)
    at com.google.appengine.datanucleus.EntityUtils.entityToPojo(EntityUtils.java:1014)
    at com.google.appengine.datanucleus.query.DatastoreQuery$2.apply(DatastoreQuery.java:229)
    at com.google.appengine.datanucleus.query.DatastoreQuery$2.apply(DatastoreQuery.java:226)
    at com.google.appengine.datanucleus.query.LazyResult.resolveNext(LazyResult.java:96)
    at com.google.appengine.datanucleus.query.LazyResult.resolveAll(LazyResult.java:121)
    at com.google.appengine.datanucleus.query.LazyResult.size(LazyResult.java:115)
    at com.google.appengine.datanucleus.query.StreamingQueryResult.size(StreamingQueryResult.java:151)
    at com.adaptavant.distributedsource.dao.ContactDAO.getContactByOwner(ContactDAO.java:450)
    at com.synclio.controller.ContactsMain.getFriendsList(ContactsMain.java:135)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_$1.run(Method_.java:167)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.privilegedInvoke(Method_.java:164)
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke_(Method_.java:125)
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke(Method_.java:43)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
    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.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:57)
    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 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.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:266)
    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 com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:438)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:480)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:487)
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:774)
    at com.google.tracing.TraceContext$DoInTraceContext.runInContext(TraceContext.java:751)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:342)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:334)

Attached are the specific java files that cause this issue and the method 
acting on them is:

    public static List<Contact> getContactByOwner(List<String> ownerID) {
        PersistenceManager pm = null;
        List<Contact> contactListFromDb = new ArrayList<Contact>();
        List<Contact> lContact = new ArrayList<Contact>();
        try {
            mLogger.info("getContactByOwner:: starting query...");
            pm = PMF.get().getPersistenceManager();
            Query query = pm.newQuery(Contact.class, "ownerID == :ownerID && deleted == false");
            query.setOrdering("firstName asc");
            mLogger.info("getContactByOwner:: executing query with ownerID " + ownerID);
            lContact = (List<Contact>) query.execute(ownerID);
            mLogger.info("getContactByOwner:: after execute");
            // mLogger.info("ContactList" + lContact);
            // mLogger.info("ContactList Size:::" + lContact.size());
            if (lContact != null) {
                if (lContact.size() > 0) {
                    Iterator<Contact> iterator = lContact.iterator();
                    while (iterator.hasNext()) {
                        Contact lTouchContact = iterator.next();
                        mLogger.info("getContactByOwner:: Got contact" + lTouchContact);
                        List<ContactMethod> lContactMethods = lTouchContact.getListOfContactMethod();
                        Iterator<ContactMethod> conatctMethodIterator = lContactMethods.iterator();
                        while (conatctMethodIterator.hasNext()) {
                            mLogger.info("getContactByOwner:: Got contact method " + conatctMethodIterator.next());
                        }
                    }

                }
                contactListFromDb.addAll(pm.detachCopyAll(lContact));
            }
        } catch (Exception e) {
            mLogger.log(Level.WARNING, e.getMessage(), e);
        } finally {
            mLogger.info("pm is " + pm);
            if (pm != null) {
                pm.close();
            }
        }
        return contactListFromDb;
    }

the line "if (lContact.size() > 0) {" causes the exception to be thrown. The 
log also contains the warning:

com.google.appengine.datanucleus.MetaDataValidator warn: Meta-data warning for 
com.adaptavant.distributedsource.objects.Contact.listOfLocation: Error in 
meta-data for com.adaptavant.distributedsource.objects.Contact.listOfLocation : 
The datastore does not support joins and therefore cannot honor requests to 
place related objects in the default fetch group.  The field will be fetched 
lazily on first access.  You can modify this warning by setting the 
datanucleus.appengine.ignorableMetaDataBehavior property in your config.  A 
value of NONE will silence the warning.  A value of ERROR will turn the warning 
into an exception.

Original issue reported on code.google.com by shaun.cl...@a-cti.com on 24 Apr 2013 at 6:48

Attachments: