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

发布于 2024-11-14 14:02:50 字数 3186 浏览 1 评论 0原文

你能告诉我我的问题是什么吗?我有 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) 方法存在一些问题,但我正在实施它们。

预先感谢您,非常感谢您的帮助。

Could you tel me please what my problem is? I have GWT RequestContext with some methods in it and some service class with that methods implementation. When I run in Dev mode my RequestContext object doesn't pass validation.

Here is the RequestContext interface:

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

and here is the implementation specified by the 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();
    }
}

}

I am getting this error about request context validation:

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

It has some problem with persist(CorporateAccount corpAcc) and remove(CorporateAccount corpAcc) methods defined in my RequestContext but I am implementing them.

Thank you in advance, I appreciate your help.

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

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

发布评论

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

评论(1

方觉久 2024-11-21 14:02:50

您应该仔细阅读日志,它们的信息非常丰富:

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

InstanceRequest<CorporateAccountProxy, Void> remove();

在 CorporateAccountService 中,您的

public void remove(CorporateAccount corporateAccount)

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

  1. 尝试更改方法以使它们匹配
  2. ,或者如果您想将实体实现为 ACTIVE RECORDS :这些实体封装了自己的持久性逻辑(就像您使用remove()所做的那样),那么您应该将所有与持久性相关的逻辑放在实体类本身中。但是您必须确保 @Serice 注释针对您的实体类而不是服务实现。

在处理 REquestFactory 时,您还应该检查以下一些规则:

  1. 确保您的实体类具有 @version 和 @Id 列及其各自的 getter/setter。版本列被 requestFactory 用于检查客户端显示的状态是否与服务器上的相同。
  2. 确保您在服务中定义一个名为 findXXX(Long id)静态方法,其中 XXX 是您的实体的名称。就你而言,我想它必须像

    public static CorporateAccount findCorporateAccount(Long id)

  3. 不要失去信心;-)

我希望这有帮助...

You should read the logs carefully, they are pretty informative :

in your CorporateAccountServiceRequest Request Context you have the following signature :

InstanceRequest<CorporateAccountProxy, Void> remove();

in the CorporateAccountService you have

public void remove(CorporateAccount corporateAccount)

The methods must match because CorporateAccountServiceRequest is a proxy (a representing interface of) your service on the client Side. If they don't match then it's not ok.
I guess the other logs are also like this one so keep reading...
In order to correct it, you should :

  1. Try to change the method so that they match
  2. or if you want to implement your Entities as ACTIVE RECORDS : which are Entities encapsulating their own peristence logic (like what you have done with remove()), then you should put all persistence-related logic in the Entity class itself. But you have to ensure that the @Serice annotation targets your Entity class instead of your Service implementation.

You should also check some of the following rules when dealing with REquestFactory :

  1. Ensure that your Entity classes have a @version and @Id columns and their respective getters/setters. Version column are used by requestFactory to check whether the state displayed on the client side is the same as on the server.
  2. Ensure that you define in your service a static method called findXXX(Long id) where XXX is the name of your Entity. In your case, I guess it has to be stg like

    public static CorporateAccount findCorporateAccount(Long id)

  3. don't lose faith ;-)

I hope this helped ...

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