简体   繁体   English

GWT RequestFactory不持久附加实体

[英]GWT RequestFactory not persisting attached entities

I'm trying to get the hang of the new RequestFactory API and having a really tough time of it. 我正试图了解新的RequestFactory API,并且非常艰难。

My domain models consist of a Staffer , a Person and an Office . 我的域模型包括StafferPersonOffice 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. 当我尝试将更新保存到GWT中的Staffer实例时,在服务器端persist()调用中,我在其原始/字符串字段中看到更新,但是我没有看到附加的PersonOffice对象的更新。 Here is how I'm affecting the edits on the GWT side: 以下是我如何影响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();
}

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: 我的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();

}

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. RequestFactory不会将persist()方法视为特殊内容,因此您必须自己实现链式持久性,或者配置ORM系统为您执行此操作。 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. 要检查的另一件事是,如果findPerson()findPerson()findOffice()方法将返回Person或Office对象的同一对象实例。 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. 如果在传入的HTTP请求的整个生命周期中使用相同的EntityManager (或系统的等效项),那通常会处理非平凡有效负载图的“缺失更新”问题。

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? 如果这没有帮助,您可以发布域对象的findFoo()persist()方法的示例吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM