数据传输对象中的com.google.gwt.user.client.rpc.SerializationException

时间:2012-01-05 11:29:10

标签: hibernate gwt serialization dto

我正在开发一个将GWT和Hibernate互连的应用程序。从GWT服务器端,我有以下代码:

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

从Hibernate方面来看,有一个Alarm类:

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 = com.cartif.dtos.EnergyDTO@16b4be5
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)

我遵循与其他objetc相同的策略,它的工作原理。我不知道为什么它现在不运行。有人能帮助我吗?

谢谢!

2 个答案:

答案 0 :(得分:0)

Docs say

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

试一试。

答案 1 :(得分:0)

我解决了这个问题。我已经通过String属性更改了双重属性,并且它可以正常工作。