2011-12-14 49 views
1

的數組列表我有2個班,其得到保存在谷歌的數據存儲。該產品包含產品細節的陣列列表。現在我很難讓ArrayList返回給我。 類產品是可拆卸的,當我嘗試存取權限對象內部ArrayList中我得到的錯誤:JDO分離對象,然後獲取該對象

You have just attempted to access field "productDetailsArray" yet this field was not detached when you detached the object. Either dont access this field, or detach it when detaching the object. 

任何人都可以解釋如何我還可以分離從谷歌的數據存儲ArrayList中?

2類即時通訊使用的是

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true") 
public class Product implements Serializable{ 
    private static final long serialVersionUID = 1L; 
    private static final Logger log = Logger.getLogger(Product.class.getName()); 
    @PrimaryKey 
    @Persistent 
    private String productNaam; 
    @Persistent 
    private String categorie; 
    @Persistent 
    private ArrayList<ProductDetails> productDetailsArray = new ArrayList<ProductDetails>(); 

    //getters and setter below. 

    // I use this methode to fix a error resulting the arraylist from being org.datanucleus.sco.backed.ArrayList 
    public void fix() { 
    log.info("Fix()"); 
    ArrayList<ProductDetails> a = new ArrayList<ProductDetails>(); 
    Iterator<ProductDetails> itr = productDetailsArray.iterator(); 
    while (itr.hasNext()) { 
     ProductDetails p = itr.next(); 
     log.info(p.getPlaats()); 
     a.add(p); 
    } 
    } 
} 

CLASSE產品詳細

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true") 
public class ProductDetails implements Serializable{ 
    private static final long serialVersionUID = 1L; 
    @PrimaryKey  
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) 
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true") 
    private String encodedKey; 
    @Persistent 
    private String winkel, plaats; 
    @Persistent 
    private double prijs; 
    //getters and setters here. 
} 

我使用的梅索德是德DAO實現返回的對象與有ArrayList的是。

public ArrayList<Product> productList() { 
    PersistenceManager pm = PmfSingleton.get().getPersistenceManager(); 
    ArrayList<Product> products = new ArrayList<Product>(); 
    try { 
     products.clear(); 
     pm.currentTransaction().begin(); 
     Extent<Product> ex = pm.getExtent(Product.class, true); 
     Iterator<Product> itr = ex.iterator(); 
     while(itr.hasNext()) { 
      Product tempProduct = itr.next(); 
      Product product = pm.detachCopy(tempProduct); 
      //ArrayList<ProductDetails> pd = new ArrayList<ProductDetails>(product.getProductDetails()); 
      product.fix(); 
      products.add(product); 
     } 
     pm.currentTransaction().commit(); 
     ex.closeAll(); 
    } catch (Exception e) { 
     pm.currentTransaction().rollback(); 
     throw new RuntimeException(e); 
    } finally { 
     pm.close(); 
    } 
    return products; 
} 

回答

2

爲什麼不遵循該消息的建議嗎?如果要分離它,請將該字段放在提取組中。對於DataNucleus將文檔告訴不夠清楚該怎麼做

+0

我使用Spring的OpenEntityManagerInViewFilter所以我不期待檢索和訪問在同一個網頁請求時要分離的對象。渴望和獲取組是一種選擇,但我很好奇爲什麼我需要。我的猜測是當我改變另一個錯誤的配置設置時引入的。 – 2012-05-31 15:54:26