2012-01-05 140 views
0

我正在開發一個互連GWT和Hibernate的應用程序。從GWT服務器端我有以下代碼:數據傳輸對象中的com.google.gwt.user.client.rpc.SerializationException

@Override 
public List<AlarmDTO> getAlarms() throws Exception{ 
    return deviceService.getAlarms(); 
} 

從休眠方面,有一個報警類別:

public List<AlarmDTO> getAlarms() { 
    @SuppressWarnings("unchecked") 
    List<Alarm> alarms = new ArrayList<Alarm>(DatabaseManager.createQuery("from Alarm")); 
    List<AlarmDTO> alarmsDTOs = new ArrayList<AlarmDTO>(alarms != null ? alarms.size() : 0); 
    if (alarms != null) { 
     for (Alarm alarm : alarms) { 
      String date = format.format(alarm.gettDate()); 
      alarmsDTOs.add(new AlarmDTO(alarm.getiAlarmId(),alarm.getsDescription(),alarm.getsCause(),date,alarm.iSetPointId,alarm.getiDeviceId())); 
     } 
    } 
    return alarmsDTOs; 
} 

它返回AlarmDTO對象的名單。這種類型的對象是一個數據傳輸對象。它的代碼是:

public class AlarmDTO implements Serializable{ 
    private static final long serialVersionUID = 1L; 
    private int iAlarmId; 
    private String sDescription; 
    private String sCause; 
    private String sDate; 
    private int iSetPointId; 
    private int iDeviceId; 

    public AlarmDTO(){} 

    public AlarmDTO(int iAlarmId,String sDescription,String sCause,String sDate,int iSetPointId,int iDeviceId){ 
    this.iAlarmId = iAlarmId; 
    this.sDescription = sDescription; 
    this.sCause = sCause; 
    this.sDate = sDate; 
    this.iSetPointId = iSetPointId; 
    this.iDeviceId = iDeviceId; 
    } 
} 

然而,當我運行應用程序,它拋出一個異常com.google.gwt.user.client.rpc.SerializationException:

Exception while dispatching incoming RPC call 
com.google.gwt.user.client.rpc.SerializationException: Type 'com.cartif.dtos.EnergyDTO' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = [email protected] 
at  com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:615) 
at  com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126) 
at com.google.gwt.user.client.rpc.core.java.util.Collection_CustomFieldSerializerBase.serialize(Collection_CustomFieldSerializerBase.java:45) 
at com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serialize(ArrayList_CustomFieldSerializer.java:40) 
at com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serializeInstance(ArrayList_CustomFieldSerializer.java:50) 
at com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serializeInstance(ArrayList_CustomFieldSerializer.java:28) 
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:736) 
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:617) 
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126) 
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:153) 
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:535) 
at com.google.gwt.user.server.rpc.RPC.encodeResponse(RPC.java:616) 
at com.google.gwt.user.server.rpc.RPC.encodeResponseForSuccess(RPC.java:474) 
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:571) 
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208) 
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248) 
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) 
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487) 
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362) 
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) 
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) 
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726) 
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) 
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206) 
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) 
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
at org.mortbay.jetty.Server.handle(Server.java:320) 
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) 
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:842) 
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:648) 
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) 
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) 
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395) 
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450) 

我遵循同樣的策略其他objetcs和它的作品。我不知道爲什麼它現在不運行。有人能幫助我嗎?

謝謝!

+0

您還有AlarmDTO的獲取者/設置者?嘗試一個乾淨的構建。 – milan 2012-01-05 11:31:21

+1

您可以分享更多關於異常的信息嗎 - 發送時是在服務器上發生,還是在客戶端嘗試讀取時發生?另外,AlarmDTO類是否可以轉換爲客戶端代碼(與其他工作DTO相同)? – 2012-01-05 22:07:54

+0

我爲EnergyDTO添加了與AlarmDTO類似的ExceptionDTO – 2012-01-10 07:01:51

回答

0

我解決了這個問題。我通過字符串屬性更改了雙重屬性,它起作用。

0

Docs say

Fields that are declared final are also not exchanged during RPCs, so they should 
generally be marked `transient`. 

試試看吧。

+0

我只聲明瞭最終的serialVersionUID,但它不是重要的屬性。 – 2012-01-10 06:57:31

相關問題