我在我的实体中使用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告诉我;))我可以Long
从 RequestContext 中的 persist() 方法返回 id。这不会从 中检索持久 id EntityProxyId
,但它确实在单个请求中为我获取了新对象的持久 id。
我将保留这个问题 - 我仍然对从 EntityProxyId 中获取持久 id 感兴趣。