簡體   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