George
George

Reputation: 255

GWT app cannot find matching method from my RequestContext interface

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.

Upvotes: 2

Views: 3436

Answers (1)

kaffein
kaffein

Reputation: 1766

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 ...

Upvotes: 2

Related Questions