【发布时间】:2011-06-30 20:16:42
【问题描述】:
我在我的实体中使用Long id,不仅将它们存储在数据存储中,还用于引用其他实体。现在,我使用 RequestFactory 在客户端上创建()对象并持久化它们,但我需要一种方法来确定服务器生成的 id。
这是我想出的一种需要两次旅行的方法:
final OrganizationProxy proxy = context.create(OrganizationProxy.class);
context.persist().using(proxy).fire(new Receiver<Void>(){
public void onSuccess(Void response)
{
requestFactory.find(proxy.stableId()).fire(new Receiver<OrganizationProxy>()
{
public void onSuccess(OrganizationProxy response)
{
//hey, now response has the server-generated id in it, along with any other values the server populated
}
});
}
});
但似乎必须有一种方法可以在没有第二次旅行的情况下获得持久ID。似乎 requestFactory.find() 首先需要持久 id 才能工作。
如何在不向服务器发出第二次请求的情况下获取持久 ID?
=======更新=======
我终于想到(在 tbroyer told me ;) 之后)我可以从 RequestContext 中的 persist() 方法返回 Long id。这不会从 EntityProxyId 检索持久 id,但它确实在单个请求中为我获取了新对象的持久 id。
我将保留这个问题 - 我仍然有兴趣从 EntityProxyId 中获取持久 id。
【问题讨论】:
标签: gwt requestfactory