2013-04-11 56 views
0

我試圖通過使用DataNucleus持久兩個類來創建一個DTO對象。從兩個表中創建新對象JDO DataNucleus

的DTO我想創建:

@PersistenceAware 
DtoObject{ 

    Protected String Id; //populated by Order class 
    Protected String status; //populated by Order class 
    Protected String phoneNumber; //populated by Customer class 
    Protected String address; //populated by Customer class 
} 
The Objects: 

@PersistenceCapable 
@FetchGroup(name="dto", members = {@Persistent(name = "Id"), 
@Persistent(name="status")}) 
public Class Order{ 
    @PrimaryKey 
    @Persistent 
    private String Id; 
    @Persistent 
    private String status; 
    @Persistent 
    private Customer customer; 
} 

@PersistenceCapable 
@FechGroup(name="dto", members = { @Persistent(name = "phoneNumber"), 
@Peristent(name="address") }) 
public Class Customer{ 

    @PrimaryKey 
    @Persistent 
    private String Id; 
    @Persistent 
    private String phoneNumber; 
    @Persistent 
    private string Address; 
} 

的JDODL:

Query q = pm.newQuery(Order.class); 
      pm.getFetchPlan().setGroup("dto"); 
      q.setUnique(true); 
      q.setFilter("Id == id"); 
      q.declareParameters("String id"); 
      q.setResultClass(DtoObject.class); 
      DtoObject dto = (DtoObject)q.execute(id); 

我可以填充映射到Order.class其屬性的DTO對象,但不能從屬性Customer.class。 Data Nucleus加入表格並從每個表格中選擇適當的列,但留下phoneNumber = null和address = null;

指導如何使這項工作與一個查詢將不勝感激。

回答

0
Query q = pm.newQuery("SELECT UNIQUE this.id, this.status, " + 
    " this.customer.phoneNumber, this.customer.address INTO " + 
    DtoObject.class.getName() + 
    " FROM " + Order.class.getName() + " WHERE this.id = :id"); 
DtoObject dto = (DtoObject)q.execute(idParam); 

假設結果類(DtoObject)服從the conditions of a result class

+0

謝謝,這工作。 – Andrew 2013-04-17 17:57:57

相關問題