0

我试图通过使用 DataNucleus 持久化两个类来创建 DTO 对象。

我希望创建的 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;

将不胜感激有关如何使用一个查询进行这项工作的指针。

4

1 回答 1

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)服从结果类的条件

于 2013-04-16T06:51:37.243 回答