2012-04-11 150 views
0

我開發了幾個GWT Web應用程序。最新的一個是對另一個的一點修改。除了最新版本之外,它們都運行良好。例外是:GWT錯誤:響應無法反序列化

The response could not be deserialized 

我在Hibernate和GWT之間使用Hibernate和數據傳輸對象。每個DTO實現java.io.Serializable接口。正如我之前所說的,在其他應用程序中運行良好。有人可以幫我解決這個錯誤嗎?我不知道原因是什麼。

我的休眠對象代碼是:

public List<AttributeDTO> getAttributes(){ 
    String sql = "from Attribute where (select max(tDate) from Attribute)-tDate < '0 days 00:05'"; 
    List<Attribute> attributes = new ArrayList<Attribute>(DatabaseManager.createQuery(sql)); 
    List<AttributeDTO> attributeDTOs = new ArrayList<AttributeDTO>(attributes != null ? attributes.size() : 0); 
    if (attributes != null) { 
     for (Attribute attribute : attributes) { 
      String date = format.format(attribute.gettDate()); 
      attributeDTOs.add(new AttributeDTO(attribute.getiAttrId(),attribute.getsName(),attribute.getsValue(),date,attribute.getiDeviceId(),attribute.getsUnits(),new ApplicationFieldDTO())); 
     } 
    } 
    return attributeDTOs; 
} 

而且AttributeDTO是:

public class AttributeDTO implements Serializable { 
    private static final long serialVersionUID = 1L; 
    private int iAttrId; 
    private String name; 
    private String value; 
    private String date; 
    private String units; 
    private int iDeviceId; 
    private ApplicationFieldDTO appField; 

    public AttributeDTO() {} 

    public AttributeDTO(int attrId, String name, String value, String date, int deviceId, String units, ApplicationFieldDTO appField) { 
     this.iAttrId = attrId; 
     this.name = name; 
     this.value = value; 
     this.date = date; 
     this.iDeviceId = deviceId; 
     this.units = units; 
     this.appField = appField; 
    } 
} 

從GWT是返回AttributeDTO的List呼叫的getAttributes()方法。

謝謝!而不是List

+0

您應該發佈DTO的代碼,這會給您帶來麻煩 – 2012-04-11 05:58:37

回答

1

如果只有一個類的成員不可序列化,那麼錯誤也會出現 - 因此錯誤也可能出現在ApplicationFieldDTO的定義中。

順便說一句,而不是使用數據傳輸對象,你也可以使用Gilead,然後,即使延遲加載工作。 (但是在現有應用程序中引入Gilead可能需要很多工作。)

+0

謝謝,它似乎很有趣。我會研究這種可能性 – 2012-04-16 07:53:19

0

使用ArrayList,並嘗試在這個post再次

看。

+0

同樣的例外... – 2012-04-11 06:37:38

+0

'new ApplicationFieldDTO()'也許這是它?這個類是序列化的還是有一個空的構造函數,不使用像List這樣的泛型類型? – GingerHead 2012-04-11 07:06:45

+0

ApplicationDTO是另一個DTO類和代碼是:公共類ApplicationFieldDTO實現Serializable {公共ApplicationFieldDTO(){}} – 2012-04-11 07:16:02

0

我有同樣的麻煩。嘗試使用com.google.gwt.user.client.rpc.IsSerializable而不是Serializable。它對我有用,我希望對你有所幫助:)

+0

在第一次開發中,我使用了com.google.gwt.user.client.rpc.IsSerializable,之後我通過java.io進行了更改。可串行化,因爲它不起作用。我認爲這不是問題,但感謝您的回覆 – 2012-04-11 06:37:08

+0

@JoseHdez您可以將異常的堆棧跟蹤附加到問題上嗎? – cardamo 2012-04-11 06:43:05