2011-04-21 61 views
0

使用GWT(2.0)+ EJB(3.x)+ JPA部署在GlassFish中並使用Eclipse Helios J2EE的真正特定即時消息。使用具有GWT + EJB + JPA的實體

我在我的EJB項目中有兩個實體:客戶端和提供者實體。使用RPC,我從GWT調用EJB項目,以回收一些實體並將它們發送回GWT項目。這個電話是這樣的:

GWT從EJB調用findClient使用EntityManager找到一個Client實體並將其返回給GWT。然而,當我嘗試complie我的GWT項目中,我得到以下

Compiling module com.MYPROJECT 
    Validating newly compiled units 
     [ERROR] Errors in 'file:/.....****....../GreetingService.java' 
     [ERROR] Line 20: No source code is available for type com.MYPROJECT.entities.Client; did you forget to inherit a required module? 
     [ERROR] Line 26: No source code is available for type com.MYPROJECT.entities.Provider; did you forget to inherit a required module? 
     [ERROR] Errors in 'file:/C:/workspaces/...***.../GreetingServiceAsync.java' 
     [ERROR] Line 14: No source code is available for type com.MYPROJECT.entities.Client; did you forget to inherit a required module? 
     [ERROR] Line 16: No source code is available for type com.MYPROJECT.entities.Provider; did you forget to inherit a required module? 

回答

2

錯誤消息說,這一切,即使你可能沒有意識到這一點(我有同樣的問題)。 GWT將Java代碼編譯成JavaScript代碼,併爲此需要的源代碼。您可能包含其他庫中提及的實體,因此這些源代碼不可用,因此GWT無法完成它的工作。

您(不幸)需要做的是在您的項目中創建一個單獨的對象並將數據從您的實體拖動(即移動)到這個新對象。

你必須確保你以正確的方式移動數據,即類似如下:

static copyDataToGwtObject(MyObj obj) { 
    MyGwtObject gwtObj = new MyGwtObject(); 
    gwtObj.setValueA(obj.getValueA()); 
    gwtObj.setValueB(obj.getValueB()); 
} 

什麼會(不幸)無法正常工作是做數據的構造運動在MyGwtObject :-(,即做這樣的事情:

class MyGwtObject { 
    private String valueA; 
    private String valueB; 
    public MyGwtObject(MyObj obj) { 
     this.valueA = obj.getValueA(); 
     this.valueB = obj.getValueB(); 
    } 
} 

這是行不通的,因爲GWT將(再次)需要構造的源代碼

+0

謝謝,它工作完美! – fernandohur 2011-04-21 15:08:00

0

是您GreetingService一個RemoteService?我用它來「翻譯」服務器返回到我在客戶端項目中創建的等效對象的對象:

GreetingSerciceImpl(延伸RemoteServiceServlet)我會寫:

public TestClient someMethod() { 
    Client c = ejbClass.getClient() // returns object of Client class defined in the EJB project 
    return translate(c); 
} 

private TestClient translate(Client c) { 
    TestClient tc = new TestClient(); 
    tc.setName(c.getName()); 
    return tc; 
} 

TestClient在某處定義GWT項目的客戶端代碼。

HTH

+0

謝謝,它工作完美! – fernandohur 2011-04-21 15:07:21