GWT RequestFactory不持久附加实体 [英] GWT RequestFactory not persisting attached entities

查看:53
本文介绍了GWT RequestFactory不持久附加实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图抓住新的 RequestFactory API和它的一个非常艰难的时刻。



我的域模型包含 Staffer ,a Person 办公室。 Staffer有一个Person和一个Office作为字段。



当我尝试将更新保存到GWT中的Staffer实例时,在服务器端 persist()调用我在其原始/字符串字段中看到更新,但未看到附加的 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);


$ b @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>坚持();
请求< List< StafferProxy>>得到所有();
请求< StafferProxy> findStaffer(Long id);
}
public StafferRequest stafferRequest();

@Service(Person.class)
public interface PersonRequest extends RequestContext
{
InstanceRequest< PersonProxy,Void>坚持();
请求< List< PersonProxy>>得到所有();
请求< PersonProxy> findPerson(Long id);
}
public PersonRequest personRequest();

@Service(Office.class)
public interface OfficeRequest extends RequestContext
{
InstanceRequest< OfficeProxy,Void>坚持();
请求< List< OfficeProxy>>得到所有();
请求< OfficeProxy> findOffice(Long id);
}
public OfficeRequest officeRequest();


$ / code $ / pre

解决方案

RequestFactory doesn不要把 persist()方法看作任何特殊的东西,所以你必须自己实现链式持久化或配置你的ORM系统来为你做。另一件要检查的是 findPerson() findOffice()方法返回Person的相同对象实例或如果多次调用Office对象。如果您在传入的HTTP请求的整个生命周期中使用相同的 EntityManager (或您的系统的等价物),那通常会处理重要的有效载荷的丢失更新问题图表。



博客发布关于链接持久性和跟踪链接的问题

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


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();

}

解决方案

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?

这篇关于GWT RequestFactory不持久附加实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆