繁体   English   中英

GAE数据核未获取子实体

[英]GAE Data nucleus not fetching child entities

我在App Engine SDK 1.7.3中使用JDO版本2数据核。 我在以一对多关系检索子对象时遇到问题。

contents = (Collection<ContentType>) persistenceManager.newQuery(ContentType.class).execute();

该查询返回ContentType的所有实例,但ContentType还包含未从数据库获取的其子项“ Content”的列表。

ContentType.java

public Collection<ContentType> getAllContents() {

        PersistenceManager persistenceManager = PersistenceFactory
                .getInstance().getPersistenceManager();
        Transaction transaction = persistenceManager.currentTransaction();
        Collection<ContentType> contents = null;
        try {
            transaction.begin();
            contents = (Collection<ContentType>) persistenceManager.newQuery(ContentType.class).execute();


            Logging.log("contents in getAllContents=== "+ contents);

            if(contents!=null)
                {
                Logging.log("contents size in getAllContents=== "+ contents.size());

                }

        for (ContentType contentTypeElement : contents) {
            Logging.log("inside main loop in getAllContents, contentTypeElement=== "+ contentTypeElement);
            if(contentTypeElement!=null)
            {
                Logging.log("inside main loop in getAllContents, contentTypeElement having list === "+ contentTypeElement.getContentList());

            }
            if(contentTypeElement.getContentList()!=null)
            {

            for (Content contentElement : contentTypeElement.getContentList()) {
                Logging.log("inside second loop in getAllContents");
                String contentPath = Constants.CONTENT_BASE_URL
                        + contentElement.getContentPath();
                contentElement.setContentPath(contentPath);
            }
            }
            Logging.log("At end of main loop iteration");
        }
        transaction.commit();
        } catch (Exception e) {
            transaction.rollback();
            e.printStackTrace();
            Logging.log("Exception retriving all content, detail in getAllContents: "
                    + e.toString());

        } finally {
            persistenceManager.close();
        }
        return contents;
    }

这是日志

2012-12-14 13:27:14.101
org.datanucleus.TransactionImpl internalPreCommit: >> calling preCommit on org.datanucleus.store.connection.ConnectionManagerImpl$2@873b9f
I 2012-12-14 13:27:14.102
org.datanucleus.TransactionImpl internalPreCommit: >> calling preCommit on org.datanucleus.ObjectManagerImpl@c6b8b0
I 2012-12-14 13:27:14.102
org.datanucleus.TransactionImpl preFlush: >> calling preFlush on org.datanucleus.store.connection.ConnectionManagerImpl$2@873b9f
I 2012-12-14 13:27:14.102
org.datanucleus.TransactionImpl preFlush: >> calling preFlush on org.datanucleus.ObjectManagerImpl@c6b8b0
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: contents in getAllContents=== [com.test.igreetings.persistence.domain.ContentType@14fdb76, com.test.igreetings.persistence.domain.ContentType@1d15a18, com.test.igreetings.persistence.domain.ContentType@171f735, com.test.igreetings.persistence.domain.ContentType@1bf496b]
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: contents size in getAllContents=== 4
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: inside main loop in getAllContents, contentTypeElement=== com.test.igreetings.persistence.domain.ContentType@14fdb76
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: inside main loop in getAllContents, contentTypeElement having list === null
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: At end of main loop iteration
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: inside main loop in getAllContents, contentTypeElement=== com.test.igreetings.persistence.domain.ContentType@1d15a18
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: inside main loop in getAllContents, contentTypeElement having list === null
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: At end of main loop iteration
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: inside main loop in getAllContents, contentTypeElement=== com.test.igreetings.persistence.domain.ContentType@171f735
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: inside main loop in getAllContents, contentTypeElement having list === null
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: At end of main loop iteration
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: inside main loop in getAllContents, contentTypeElement=== com.test.igreetings.persistence.domain.ContentType@1bf496b
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: inside main loop in getAllContents, contentTypeElement having list === null
I 2012-12-14 13:27:14.135
com.test.igreetings.util.Logging log: At end of main loop iteration
I 2012-12-14 13:27:14.136
org.datanucleus.TransactionImpl internalPreCommit: >> calling preCommit on org.datanucleus.store.connection.ConnectionManagerImpl$2@66da2c
I 2012-12-14 13:27:14.136
org.datanucleus.TransactionImpl internalPreCommit: >> calling preCommit on org.datanucleus.ObjectManagerImpl@274608

数据核日志

1.  org.datanucleus.store.connection.ConnectionManagerImpl allocateConnection: Connection added to the pool : com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl$DatastoreManagedConnection@74ece8 for key=org.datanucleus.ObjectManagerImpl@107c76b in factory=ConnectionFactory:tx[com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl@119549e]
2.  
3.  D2012-12-14 17:20:11.232
4.  org.datanucleus.store.query.QueryManager getQueryCompilationForQuery: Query "SELECT FROM com.test.igreetings.persistence.domain.ContentType" of language "JDOQL" has been run before so reusing existing generic compilation
5.  D2012-12-14 17:20:11.232
6.  com.google.appengine.datanucleus.query.JDOQLQuery performExecute: JDOQL Query : Executing "SELECT FROM com.test.igreetings.persistence.domain.ContentType" ...
7.  D2012-12-14 17:20:11.233
8.  com.google.appengine.datanucleus.query.JDOQLQuery performExecute: Query compiled as : Kind=com.test.igreetings.persistence.domain.ContentType
9.  D2012-12-14 17:20:11.233
10. com.google.appengine.datanucleus.query.DatastoreQuery executeNormalQuery: Executing query in datastore for SELECT FROM com.test.igreetings.persistence.domain.ContentType
11. D2012-12-14 17:20:11.233
12. org.datanucleus.store.connection.ConnectionManagerImpl allocateConnection: Connection found in the pool : com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl$DatastoreManagedConnection@74ece8 for key=org.datanucleus.ObjectManagerImpl@107c76b in factory=ConnectionFactory:tx[com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl@119549e]
13. D2012-12-14 17:20:11.234
14. com.google.appengine.datanucleus.query.JDOQLQuery performExecute: JDOQL Query : Execution Time = 2 ms
15. D2012-12-14 17:20:11.279
16. org.datanucleus.ObjectManagerImpl getObjectFromLevel1Cache: Object with id "com.test.igreetings.persistence.domain.ContentType:ContentType(3)" not found in Level 1 cache [cache size = 0]
17. D2012-12-14 17:20:11.279
18. org.datanucleus.ObjectManagerImpl putObjectIntoLevel1Cache: Object "com.test.igreetings.persistence.domain.ContentType@165d118" (id="com.test.igreetings.persistence.domain.ContentType:ContentType(3)") added to Level 1 cache (loadedFlags="[NNYNN]")
19. D2012-12-14 17:20:11.279
20. org.datanucleus.state.JDOStateManager wrapSCOField: Object "com.test.igreetings.persistence.domain.ContentType@165d118" (id="com.test.igreetings.persistence.domain.ContentType:ContentType(3)") is having the value in field "endDate" replaced by a SCO wrapper
21. D2012-12-14 17:20:11.280
22. org.datanucleus.state.JDOStateManager wrapSCOField: Object "com.test.igreetings.persistence.domain.ContentType@165d118" (id="com.test.igreetings.persistence.domain.ContentType:ContentType(3)") is having the value in field "startDate" replaced by a SCO wrapper
23. D2012-12-14 17:20:11.280
24. org.datanucleus.ObjectManagerImpl enlistInTransaction: Object "com.test.igreetings.persistence.domain.ContentType@165d118" (id="com.google.appengine.api.datastore.Key:ContentType(3)") enlisted in transactional cache
25. D2012-12-14 17:20:11.280
26. org.datanucleus.ObjectManagerImpl getObjectFromLevel2Cache: Object with id="com.test.igreetings.persistence.domain.ContentType:ContentType(3)" taken from Level 2 cache (fields="[0, 1, 2, 3, 4]", version="") - represented as "com.test.igreetings.persistence.domain.ContentType@165d118"
27. D2012-12-14 17:20:11.280
org.datanucleus.store.connection.ConnectionManagerImpl allocateConnection: Connection found in the pool : com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl$DatastoreManagedConnection@74ece8 for key=org.datanucleus.ObjectManagerImpl@107c76b in factory=ConnectionFactory:tx[com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl@119549e]

因此,尽管在管理控制台数据查看器中有许多与内容类型相关联的Content实例,但contentList被提取为空。 我想念什么?

由于您现在说的是List的ContentType中没有属性,因此您没有使用GAE JDO插件的v2保留数据。 因此,您不能期望它了解Collection中的元素。

解决方案:修复您的数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM