0

加载 GWT 页面时遇到此错误:

错误com.google.gwt.user.client.rpc.SerializationException: Type 'com.summerbreezemotel.server.DBReservation'未包含在可由此 SerializationPolicy 序列化的类型集中,或者无法加载其 Class 对象。

我查看了文档,似乎遵循了所有的限制。我还有 3 个其他类做同样的事情,但是这个似乎会引起问题。任何帮助,将不胜感激。

类是failing:DBReservation

    package com.summerbreezemotel.server;
    import java.util.Date;

    import com.google.appengine.api.datastore.DatastoreService;
    import com.google.appengine.api.datastore.DatastoreServiceFactory;
    import com.google.appengine.api.datastore.Entity;
    import com.google.appengine.api.datastore.Key;
    import com.google.appengine.api.datastore.KeyFactory;
    import com.summerbreezemotel.shared.DataReservation;
    import com.summerbreezemotel.shared.SiteConstants;

    public class DBReservation extends DataReservation
    {
      /**
       * 
       */
      private static final long serialVersionUID = 146606067638056872L;
      Date dateReserved;
      String userEmail;

      public DBReservation() {}

      public DBReservation(DataReservation in) {
        checkIn = in.checkIn;
        checkOut = in.checkOut;
        form_FirstName = in.form_FirstName;
        form_LastName = in.form_LastName;
        form_Addr1 = in.form_Addr1;
        form_Addr2 = in.form_Addr2;
        form_City = in.form_City;
        form_State = in.form_State;
        form_Zip = in.form_Zip;
        form_Country = in.form_Country;
        form_Phone = in.form_Phone;
        form_Email = in.form_Email;
        form_CardType = in.form_CardType;
        form_CardMonth = in.form_CardMonth;
        form_CardNumber = in.form_CardNumber;
        form_CardYear = in.form_CardYear;
        form_RoomType = in.form_RoomType;
        form_isSmoking = in.form_isSmoking;
        form_numRooms = in.form_numRooms;
        ratePerNightPerRoom = in.ratePerNightPerRoom;
        totalRate = in.totalRate;   
      }

      DataReservation getData()
      {
        DataReservation out = new DataReservation();
        out.checkIn = checkIn;
        out.checkOut = checkOut;
        out.form_FirstName = form_FirstName;
        out.form_LastName = form_LastName;
        out.form_Addr1 = form_Addr1;
        out.form_Addr2 = form_Addr2;
        out.form_City = form_City;
        out.form_State = form_State;
        out.form_Zip = form_Zip;
        out.form_Country = form_Country;
        out.form_Phone = form_Phone;
        out.form_Email = form_Email;
        out.form_CardType = form_CardType;
        out.form_CardMonth = form_CardMonth;
        out.form_CardNumber = form_CardNumber;
        out.form_CardYear = form_CardYear;
        out.form_RoomType = form_RoomType;
        out.form_isSmoking = form_isSmoking;
        out.form_numRooms = form_numRooms;
        out.ratePerNightPerRoom = ratePerNightPerRoom;
        out.totalRate = totalRate;
        return out;
      }

      // gets item from DB and convertes it to this
      void fillReservationFromEntity(Entity item)
      {
        userEmail = (String) item.getProperty(SiteConstants.USER_PROPERTY);
        dateReserved = (Date) item.getProperty(SiteConstants.RESERVE_DATE_PROPERTY);
        checkIn = (Date) item.getProperty(SiteConstants.IN_DATE_PROPERTY);
        checkOut = (Date) item.getProperty(SiteConstants.OUT_DATE_PROPERTY);
        form_FirstName = (String) item.getProperty(SiteConstants.FORM_FIRSTNAME_PROPERTY);
        form_LastName = (String) item.getProperty(SiteConstants.FORM_LASTNAME_PROPERTY);
        form_Addr1 = (String) item.getProperty(SiteConstants.FORM_ADDR1_PROPERTY);
        form_Addr2 = (String) item.getProperty(SiteConstants.FORM_ADDR2_PROPERTY);
        form_City = (String) item.getProperty(SiteConstants.FORM_CITY_PROPERTY);
        form_State = (String) item.getProperty(SiteConstants.FORM_STATE_PROPERTY);
        form_Zip = (String) item.getProperty(SiteConstants.FORM_ZIP_PROPERTY);
        form_Country = (String)item.getProperty(SiteConstants.FORM_COUNTRY_PROPERTY);
        form_Phone = (String) item.getProperty(SiteConstants.FORM_PHONE_PROPERTY);
        form_Email = (String) item.getProperty(SiteConstants.FORM_EMAIL_PROPERTY);
        form_CardType = (String) item.getProperty(SiteConstants.FORM_CARDTYPE_PROPERTY);
        form_CardMonth = (String) item.getProperty(SiteConstants.FORM_CARDMONTH_PROPERTY);
        form_CardNumber = (String) item.getProperty(SiteConstants.FORM_CARDNUMBER_PROPERTY);
        form_CardYear = (Long) item.getProperty(SiteConstants.FORM_CARDYEAR_PROPERTY);
        form_RoomType = (Long) item.getProperty(SiteConstants.FORM_ROOMTYPE_PROPERTY);
        form_isSmoking = (Boolean) item.getProperty(SiteConstants.FORM_ISSMOKING_PROPERTY);
        form_numRooms = (Long) item.getProperty(SiteConstants.FORM_NUMROOMS_PROPERTY);
        ratePerNightPerRoom = (Double) item.getProperty(SiteConstants.RATEPERNIGHTPERROOM_PROPERTY);
        totalRate = (Double) item.getProperty(SiteConstants.TOTALRATE_PROPERTY);
      }

      void addReservationsToEntity(Entity item)
      {
        item.setProperty(SiteConstants.USER_PROPERTY, userEmail);
        item.setProperty(SiteConstants.RESERVE_DATE_PROPERTY, dateReserved);
        item.setProperty(SiteConstants.IN_DATE_PROPERTY, checkIn);
        item.setProperty(SiteConstants.OUT_DATE_PROPERTY, checkOut);
        item.setProperty(SiteConstants.FORM_FIRSTNAME_PROPERTY,form_FirstName);
        item.setProperty(SiteConstants.FORM_LASTNAME_PROPERTY,form_LastName);
        item.setProperty(SiteConstants.FORM_ADDR1_PROPERTY,form_Addr1);
        item.setProperty(SiteConstants.FORM_ADDR2_PROPERTY,form_Addr2);
        item.setProperty(SiteConstants.FORM_CITY_PROPERTY,form_City);
        item.setProperty(SiteConstants.FORM_STATE_PROPERTY,form_State);
        item.setProperty(SiteConstants.FORM_ZIP_PROPERTY,form_Zip);
        item.setProperty(SiteConstants.FORM_COUNTRY_PROPERTY,form_Country);
        item.setProperty(SiteConstants.FORM_PHONE_PROPERTY,form_Phone);
        item.setProperty(SiteConstants.FORM_EMAIL_PROPERTY,form_Email);
        item.setProperty(SiteConstants.FORM_CARDTYPE_PROPERTY,form_CardType);
        item.setProperty(SiteConstants.FORM_CARDMONTH_PROPERTY,form_CardMonth);
        item.setProperty(SiteConstants.FORM_CARDNUMBER_PROPERTY,form_CardNumber);
        item.setProperty(SiteConstants.FORM_CARDYEAR_PROPERTY,form_CardYear);
        item.setProperty(SiteConstants.FORM_ROOMTYPE_PROPERTY,form_RoomType);
        item.setProperty(SiteConstants.FORM_ISSMOKING_PROPERTY,form_isSmoking);
        item.setProperty(SiteConstants.FORM_NUMROOMS_PROPERTY,form_numRooms);
        item.setProperty(SiteConstants.RATEPERNIGHTPERROOM_PROPERTY,ratePerNightPerRoom);
        item.setProperty(SiteConstants.TOTALRATE_PROPERTY,totalRate);
      }

      void store()
      {
    //      UserService userService = UserServiceFactory.getUserService();
    //      User user = userService.getCurrentUser();
    //      if(user.getEmail() != null)
    //          userEmail = user.getEmail();

        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

        String SummerBreezeDateStoreName = new String(SiteConstants.KEY_NAME);
        Key SummerBreezeDateStoreKey = KeyFactory.createKey(SiteConstants.KEY_KEY, SummerBreezeDateStoreName);
        Entity reservationsEntry = new Entity(SiteConstants.DB_RESERVATIONS, SummerBreezeDateStoreKey);

        addReservationsToEntity(reservationsEntry);
        datastore.put(reservationsEntry);
        // use this if writes get to high
        //      item.setProperty("testBlob",new Blob(toByte(roomResevationRequest)));

        datastore.put(reservationsEntry);
      }
    }

我的数据预订

      package com.summerbreezemotel.shared;

      import java.io.Serializable;
      import java.util.Date;

      public class DataReservation implements Serializable
      {
        private static final long serialVersionUID = -7598404617383692994L;

        public String form_FirstName;
        public String form_LastName;
        public String form_Addr1;
        public String form_Addr2;
        public String form_City;
        public String form_State;
        public String form_Zip;
        public String form_Country;
        public String form_Phone;
        public String form_Email;
        public String form_CardType;
        public String form_CardMonth;
        public String form_CardNumber;
        public long form_CardYear;
        public long form_RoomType;
        public boolean form_isSmoking;
        public Date checkIn;
        public Date checkOut;
        public long form_numRooms;
        public double ratePerNightPerRoom;
        public double totalRate;

        public DataReservation()
        {   
        }
      }
4

3 回答 3

1

您正在共享文件夹中使用实现Serializable并在服务器端扩展它的文件。你确定这个逻辑??它通常是客户端/共享端的pojo/dto/model实现IsSerializable 并将其发送到服务器。然后服务器进行操作并将其返回。

于 2013-08-04T05:40:53.543 回答
1

我认为这是一个典型的中伤自己的案例。通过使用您创建的共享类中的逻辑扩展您的服务器对象,创建包含数据库代码的服务器端类会更容易一些,但是如果您不小心返回服务器端而不是getData()在将其发送到客户端之前调用,您会得到当然不能发送到客户端的服务器端类。但是编译器不会警告你,因为它在语法上是正确的。所以我相信答案不在给出的代码中,看起来不错,而是在 gwt servlet 和DBReservation.

于 2013-08-04T18:54:36.240 回答
0

它应该实现 Serializable 接口。您不会通过扩展类来“继承”实现。

于 2013-08-04T01:18:21.290 回答