2012-01-27 98 views
-1

我收到以下錯誤:javax.jdo.JDODetachedFieldAccessException JDO的App Engine

javax.jdo.JDODetachedFieldAccessException:您剛纔試圖訪問領域的「管理員」然而,當你脫離的對象完全沒有剝離,這個領域。要麼不訪問此字段,要麼在分離對象時將其分離。

這裏我有一個具有管理員領域的一個子類存儲對象的列表。

我第一次調用這個函數

static List<Store> getStores() { 

    PersistenceManager pm = PMF.get().getPersistenceManager(); 

    Query query = pm.newQuery(XZStore.class); 
    List<Store> stores = (List<Store>) query.execute(); 
    //need to detatch them here 
    stores = (List<Store>) pm.detachCopyAll(stores); 
    pm.close(); 
    return stores;  
} 

,然後訪問該商店的管理領域(store.admin)中的每一個。

我想如果我detachCopyAll(存儲),那麼我也detatch存儲的 元素的成員。不是嗎?

我甚至嘗試以下,但沒有運氣:

for (Store store : stores) 
    store.setAdmin(pm.detachCopy(store.getAdmin())); 

感謝,

約翰Goche的

我終於找到了解決辦法。以下爲我工作 (分離容器元素未剝離的成員 元素,我不得不分開做)。

PersistenceManager pm = PMF.get().getPersistenceManager(); 

Query query = pm.newQuery(Store.class); 
List<Store> stores = (List<Store>) query.execute(); 
//need to detatch them here 
List<Store> detachedStores = new ArrayList<Store>(); 
for (Store store : stores) { 
    Store detachedStore = pm.detachCopy(store); 
    AdminUser detachedAdmin = pm.detachCopy(store.getAdmin()); 
    detachedStore.setAdmin(detachedAdmin); 
    detachedStores.add(detachedStore); 
} 

pm.close(); 

問候,

約翰Goche的

回答

0

我還以爲那JDO文檔的讀取和JDO規範會更利於你,想獲取計劃/組特別的部分,並默認獲取組。你的「解決方案」效率低下。

+0

好,分離在不同的實體組的實體之前,我想獲得這個簡單的例子,如果在所有可能的第一份工作......,尤其是當我需要分離的東西,使之成爲持久的,如果我需要訪問後的任何時間它又是什麼? – johngoche9999 2012-01-28 23:25:37

+0

默認獲取組不讓我獲取多值屬性。 – johngoche9999 2012-01-29 13:48:01

相關問題