GWT应用程序无法从我的RequestContext接口中找到匹配方法

时间:2011-06-09 15:43:04

标签: java gwt requestfactory

请问我,请问我的问题是什么?我有GWT RequestContext,其中包含一些方法和一些带有该方法实现的服务类。当我在开发模式下运行时,我的RequestContext对象不会通过验证。

这是RequestContext接口:

@Service(value = CorporateAccountService.class, locator = CorporateAccountServiceLocator.class)

public interface CorporateAccountServiceRequest extends RequestContext {
  Request<List<CorporateAccountProxy>> findAllCorporateAccounts();
  Request<CorporateAccountProxy> findCorporateAccount(Long id);
  InstanceRequest<CorporateAccountProxy, Void> persist();
  InstanceRequest<CorporateAccountProxy, Void> remove();
}

这是ServiceLocator指定的实现:

public class CorporateAccountService {

public void persist(CorporateAccount corporateAccount) {
    EntityManager em = EMF.get().createEntityManager();
    try {
        em.persist(corporateAccount);
    } finally {
        em.close();
    }
}

public void remove(CorporateAccount corporateAccount) {
    EntityManager em = EMF.get().createEntityManager();
    try {
        CorporateAccount attached = em.find(CorporateAccount.class,
                corporateAccount.getId());
        em.remove(attached);
    } finally {
        em.close();
    }
}

@SuppressWarnings("unchecked")
public List<CorporateAccount> findAllCorporateAccounts() {
    EntityManager em = EMF.get().createEntityManager();
    try {
        List<CorporateAccount> list = em.createQuery(
                "FROM CorporateAccount").getResultList();
        // force to get all the employees
        list.size();
        return list;
    } finally {
        em.close();
    }

}

public CorporateAccount findCorporateAccount(Long id) {
    EntityManager em = EMF.get().createEntityManager();
    try {
        return em.find(CorporateAccount.class, id);
    } finally {
        em.close();
    }
}

}

我收到有关请求上下文验证的错误:

Jun 9, 2011 7:32:10 PM com.dms.admin.shared.CorporateAccountServiceRequest com.google.web.bindery.requestfactory.shared.InstanceRequest remove()
SEVERE: Could not find matching method in com.dms.admin.server.CorporateAccountService.
Possible matches:
    void remove(com.dms.admin.server.domain.CorporateAccount )

Jun 9, 2011 7:32:10 PM com.dms.admin.shared.CorporateAccountServiceRequest   com.google.web.bindery.requestfactory.shared.InstanceRequest persist()
SEVERE: Could not find matching method in com.dms.admin.server.CorporateAccountService.
Possible matches:
    void persist(com.dms.admin.server.domain.CorporateAccount )

Jun 9, 2011 7:32:10 PM com.google.web.bindery.requestfactory.server.ServiceLayerDecorator die
SEVERE: The RequestContext type com.dms.admin.shared.CorporateAccountServiceRequest did     not pass validation
Jun 9, 2011 7:32:10 PM  com.google.web.bindery.requestfactory.server.RequestFactoryServlet doPost
SEVERE: Unexpected error
com.google.web.bindery.requestfactory.server.UnexpectedException: The RequestContext  type com.dms.admin.shared.CorporateAccountServiceRequest did not pass validation

在我的RequestContext中定义的persist(CorporateAccount corpAcc)和remove(CorporateAccount corpAcc)方法存在一些问题,但我正在实现它们。

提前感谢您,感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

你应该仔细阅读日志,它们非常有用:

在您的CorporateAccountServiceRequest请求上下文中,您有以下签名:

InstanceRequest<CorporateAccountProxy, Void> remove();
您拥有的CorporateAccountService中的

public void remove(CorporateAccount corporateAccount)

方法必须匹配,因为CorporateAccountServiceRequest是客户端上的服务的代理(代表接口)。如果它们不匹配那么它就不行了。 我猜其他日志也是这样的,所以继续阅读...... 为了纠正它,你应该:

  1. 尝试更改方法以匹配
  2. 或者如果您想将实体实现为ACTIVE RECORDS:哪些实体封装了自己的执行逻辑(就像您使用remove()所做的那样),那么您应该将所有与持久性相关的逻辑放在Entity类本身中。但您必须确保@Serice注释以您的Entity类为目标而不是您的Service实现。
  3. 在处理REquestFactory时,您还应该检查以下一些规则:

    1. 确保您的Entity类具有@version和@Id列及其各自的getter / setter。 requestFactory使用Version列来检查客户端显示的状态是否与服务器上的状态相同。
    2. 确保在您的服务中定义名为 findXXX(长ID)静态方法,其中XXX是您的实体的名称。在你的情况下,我想它必须像

      一样

      public static CorporateAccount findCorporateAccount(Long id)

    3. 不要失去信心; - )

    4. 我希望这有帮助...