GWT RequestFactory 不持久保存附加实体

发布于 2024-10-17 04:36:41 字数 3260 浏览 4 评论 0原文

我正在尝试掌握新的 RequestFactory API 并拥有这是一段非常艰难的时期。

我的域模型由 StaffPersonOffice 组成。 Staffer 有一个 Person 和一个 Office 作为字段。

当我尝试将更新保存到 GWT 中的 Staffer 实例时,在服务器端 persist() 调用中,我看到其原始/字符串字段中的更新,但没有看到附加的 < code>Person 或 Office 对象。以下是我如何影响 GWT 端的编辑:

private void persistStafferDetails()
{
    CRMRequestFactory.StafferRequest stafferRequest = requestFactory.stafferRequest();
    staffer = stafferRequest.edit(staffer);

    PersonProxy person = staffer.getPerson();
    person.setFirstName(firstNameField.getText());
    person.setLastName(lastNameField.getText());

    staffer.setPersonalEmail(personalEmailField.getText());
    staffer.getHomeLocation().setStreetAddress(addressField1.getText());
    staffer.getHomeLocation().setCity(cityField.getText());
    staffer.getHomeLocation().setPostalCode(postalField.getText());
    staffer.getHomeLocation().setProvince(provinceDropDown.getValue(provinceDropDown.getSelectedIndex()));

    stafferRequest.persist().using(staffer).fire();
}

这是代理:

@ProxyFor(Staffer.class)
public interface StafferProxy extends EntityProxy
{
    Long getId();

    PersonProxy getPerson();
    void setPerson(PersonProxy person);

    OfficeProxy getOffice();
    void setOffice(OfficeProxy office);

    String getHomePhone();
    void setHomePhone(String homePhone);

    String getCellPhone();
    void setCellPhone(String cellPhone);

    String getPersonalEmail();
    void setPersonalEmail(String personalEmail);

    LocationProxy getHomeLocation();
    void setHomeLocation(LocationProxy homeLocation);
}

@ProxyFor(Person.class)
public interface PersonProxy extends EntityProxy
{
    Long getId();
    void setId(Long id);

    String getFirstName();
    void setFirstName(String firstName);

    String getLastName();
    void setLastName(String lastName);
}


@ProxyFor(Office.class)
public interface OfficeProxy extends EntityProxy
{
    Long getId();

    String getName();
    void setName(String name);
}

我的 CRMRequestFactory 如下所示:

public interface CRMRequestFactory extends RequestFactory
{
  @Service(Staffer.class)
    public interface StafferRequest extends RequestContext
    {
        InstanceRequest<StafferProxy, Void> persist();
        Request<List<StafferProxy>> getAll();
        Request<StafferProxy> findStaffer(Long id);
    }
    public StafferRequest stafferRequest();

    @Service(Person.class)
    public interface PersonRequest extends RequestContext
    {
        InstanceRequest<PersonProxy, Void> persist();
        Request<List<PersonProxy>> getAll();
        Request<PersonProxy> findPerson(Long id);
    }
    public PersonRequest personRequest();

    @Service(Office.class)
    public interface OfficeRequest extends RequestContext
    {
        InstanceRequest<OfficeProxy, Void> persist();
        Request<List<OfficeProxy>> getAll();
        Request<OfficeProxy> findOffice(Long id);
    }
    public OfficeRequest officeRequest();

}

I'm trying to get the hang of the new RequestFactory API and having a really tough time of it.

My domain models consist of a Staffer, a Person and an Office. Staffer has a Person and an Office as fields.

When I try to save updates to a Staffer instance in GWT, on the server-side persist() call I see the updates in its primitive/String fields, but I do not see updates to the attached Person or Office objects. Here is how I'm affecting the edits on the GWT side:

private void persistStafferDetails()
{
    CRMRequestFactory.StafferRequest stafferRequest = requestFactory.stafferRequest();
    staffer = stafferRequest.edit(staffer);

    PersonProxy person = staffer.getPerson();
    person.setFirstName(firstNameField.getText());
    person.setLastName(lastNameField.getText());

    staffer.setPersonalEmail(personalEmailField.getText());
    staffer.getHomeLocation().setStreetAddress(addressField1.getText());
    staffer.getHomeLocation().setCity(cityField.getText());
    staffer.getHomeLocation().setPostalCode(postalField.getText());
    staffer.getHomeLocation().setProvince(provinceDropDown.getValue(provinceDropDown.getSelectedIndex()));

    stafferRequest.persist().using(staffer).fire();
}

Here are the proxies:

@ProxyFor(Staffer.class)
public interface StafferProxy extends EntityProxy
{
    Long getId();

    PersonProxy getPerson();
    void setPerson(PersonProxy person);

    OfficeProxy getOffice();
    void setOffice(OfficeProxy office);

    String getHomePhone();
    void setHomePhone(String homePhone);

    String getCellPhone();
    void setCellPhone(String cellPhone);

    String getPersonalEmail();
    void setPersonalEmail(String personalEmail);

    LocationProxy getHomeLocation();
    void setHomeLocation(LocationProxy homeLocation);
}

@ProxyFor(Person.class)
public interface PersonProxy extends EntityProxy
{
    Long getId();
    void setId(Long id);

    String getFirstName();
    void setFirstName(String firstName);

    String getLastName();
    void setLastName(String lastName);
}


@ProxyFor(Office.class)
public interface OfficeProxy extends EntityProxy
{
    Long getId();

    String getName();
    void setName(String name);
}

And my CRMRequestFactory looks like:

public interface CRMRequestFactory extends RequestFactory
{
  @Service(Staffer.class)
    public interface StafferRequest extends RequestContext
    {
        InstanceRequest<StafferProxy, Void> persist();
        Request<List<StafferProxy>> getAll();
        Request<StafferProxy> findStaffer(Long id);
    }
    public StafferRequest stafferRequest();

    @Service(Person.class)
    public interface PersonRequest extends RequestContext
    {
        InstanceRequest<PersonProxy, Void> persist();
        Request<List<PersonProxy>> getAll();
        Request<PersonProxy> findPerson(Long id);
    }
    public PersonRequest personRequest();

    @Service(Office.class)
    public interface OfficeRequest extends RequestContext
    {
        InstanceRequest<OfficeProxy, Void> persist();
        Request<List<OfficeProxy>> getAll();
        Request<OfficeProxy> findOffice(Long id);
    }
    public OfficeRequest officeRequest();

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮生面具三千个 2024-10-24 04:36:41

RequestFactory 不会将 persist() 方法视为任何特殊的方法,因此您必须自己实现链式持久保存或配置 ORM 系统来为您执行此操作。另一件需要检查的事情是,如果多次调用,findPerson()findOffice() 方法是否返回 Person 或 Office 对象的同一对象实例。如果您在传入 HTTP 请求的整个生命周期中使用相同的 EntityManager(或系统的等效项),通常可以解决重要负载图的“缺失更新”问题。

关于链式持久化和问题的博客文章跟踪器链接,其中包含简短的讨论。

如果这没有帮助,您可以发布域对象的 findFoo()persist() 方法的示例吗?

RequestFactory doesn't treat the persist() method as anything special, so you have to implement chained persists on your own or configure your ORM system to do it for you. Another thing to check is that the findPerson() and findOffice() methods return the same object instance of the Person or Office object if called more than once. If you use the same EntityManager (or your system's equivalent) throughout the lifetime of the incoming HTTP request, that usually takes care of the "missing updates" problem with non-trivial payload graphs.

A blog post about chained persistence and an issue tracker link with a short discussion.

If this doesn't help, could you post an example of your domain objects' findFoo() and persist() methods?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文