【问题标题】:com.google.gwt.user.client.rpc.SerializationExceptioncom.google.gwt.user.client.rpc.SerializationException
【发布时间】:2011-03-22 11:08:29
【问题描述】:

我是 GAE、GWT、Hibernate 和 JDO 的新手。我有BusBusStopRoute 类,它们的序列化如下:

BaseObject.java

package org.symphony.suchitra.gae.client.admin.model;
import java.io.Serializable;
public interface BaseObject extends Serializable {
    String getId();
}

Bus.java

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Bus implements BaseObject {
    @PrimaryKey
    @Persistent(valueStrategy =IdGeneratorStrategy.IDENTITY)
    protected Long id;

    public String getId() {
        if( id == null ) {
            return null;
        }

        return id.toString();
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Persistent
    protected String busNumber;
    @Persistent
    @Unique
    protected String busIdentifier;
    @Persistent
    protected String routeId;

    public String getBusNumber() {
        return busNumber;
    }

    public void setBusNumber(String busNumber) {
        this.busNumber = busNumber;
    }

    public String getBusIdentifier() {
        return busIdentifier;
    }

    public void setBusIdentifier(String busIdentifier) {
        this.busIdentifier = busIdentifier;
    }

    public String getRouteId() {
        return routeId;
    }

    public void setRouteId(String routeId) {
        this.routeId = routeId;
    }
}

BusStop.java

@PersistenceCapable(identityType=IdentityType.APPLICATION)

public class BusStop implements BaseObject{
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    protected Long ident;

    public String getId() {
        if( ident == null ) {
            return null;
        }

        return ident.toString();
    }

    public void setId(String id) {
        this.ident = Long.parseLong(id);
    }

    @Persistent
    @Unique
    private String name;
    @Persistent
    private String latitude;
    @Persistent
    private String longitude;

    public String getLatitude() {
        return latitude;
    }

    public void setLatitude(String email) {
        this.latitude = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLongitude() {
        return longitude;
    }

    public void setLongitude(String password) {
        this.longitude = password;
    }
}

Route.java

@PersistenceCapable (identityType=IdentityType.APPLICATION)
public class Route implements BaseObject{
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    protected Long id;

    public String getId() {
        if( id == null ) {
            return null;
        }

        return id.toString();
    }

    public void setId(String id) {
        this.id = Long.parseLong(id);
    }

    @Persistent
    private String name;
    @Persistent
    private String sourceId;
    @Persistent
    private String destinationId;

    public String getSourceId() {
        return sourceId;
    }

    public void setSourceId(String source) {
        this.sourceId = source;
    }

    public String getDestinationId() {
        return destinationId;
    }

    public void setDestinationId(String destinationId) {
        this.destinationId = destinationId;
    }

    @Persistent
    private String totalDistance;
    @Persistent
    private String totalTime;
    @Persistent
    private List<Long> busStopKeys;

    @NotPersistent
    private List<BusStop> busStops;

    public String getTotalTime() {
        return totalTime;
    }

    public void setTotalTime(String totalTime) {
        this.totalTime = totalTime;
    }

    public List<BusStop> getBusStops() {
        return busStops;
    }

    public void setBusStops(List<BusStop> busStops) {
        this.busStops = busStops;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTotalDistance() {
        return totalDistance;
    }

    public void setTotalDistance(String totalDistance) {
        this.totalDistance = totalDistance;
    }

    public List<Long> getBusStopKeys() {
        return busStopKeys;
    }

    public void setBusStopKeys(List<Long> busStopKeys) {
        this.busStopKeys = busStopKeys;
    }   
}

休眠映射:

bus.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping  PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"       "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

 <hibernate-mapping>
<class name="org.symphony.suchitra.gae.client.admin.model.Bus" table="bus">
    <id column="bus_id" name="bus_id" type="java.lang.String"> 
        <generator class="org.hibernate.id.UUIDHexGenerator"> 
        </generator> 
    </id> 
    <property name="bus_number"/> 
    <property name="bus_identifier" unique="true"/>
    <property name="route_id"/>
</class>
 </hibernate-mapping>

busstop.hbm.xml

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE hibernate-mapping  PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="org.symphony.suchitra.gae.client.admin.model.BusStop" table="busstop">
    <id column="busstop_id" name="busstop_id" type="java.lang.String"> 
        <generator class="org.hibernate.id.UUIDHexGenerator"> 
        </generator> 
    </id> 
    <property name="name"/> 
    <property name="latitude"/> 
    <property name="longitude"/> 
</class>
 </hibernate-mapping>

route.hbm.xml

  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE hibernate-mapping  PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

  <hibernate-mapping>
<class name="org.symphony.suchitra.gae.client.admin.model.Route">
    <id column="route_id" name="route_id" type="java.lang.String"> 
        <generator class="org.hibernate.id.UUIDHexGenerator"> 
        </generator> 
    </id> 
    <property name="name"/> 
    <property name="source"/>
    <property name="destination"/>
    <property name="total_distance"/> 
    <property name="total_time"/>
    <list name="busstoplist" table="busstoplist" cascade="save-update"> 
        <key column="route_id"/> 
        <list-index column="busstoplist_id"/> 
        <many-to-many class="org.symphony.suchitra.gae.client.admin.model.BusStop"   column="busstop_id"/>
    </list> 
</class>
  </hibernate-mapping>

在这里,路线和公交车站是多对多的关系,每辆公交车都有一条路线。 我只是将路线的 ID 存储在公共汽车中,但是,在检索公共汽车对象时, 它给出了以下错误

com.google.gwt.user.client.rpc.SerializationException: 类型 'org.datanucleus.sco.backed.ArrayList' 未包含在可由此 SerializationPolicy 序列化的类型集中或其类对象不能被加载。出于安全考虑,此类型不会被序列化。: instance

存储时没有问题。现在我不直接处理 Bus 对象中的 ArrayList。 所以我无法弄清楚在哪里操作 datanucleus ArrayList 对象 实用数组列表。

此外,当我将 busstop id 而不是 route id 存储在 bus 表中时,程序运行良好。获取总线对象后,我将显示其详细信息。这样做时,我通过 RouteDAO 检索路由对象的名称字段。

请帮帮我...

【问题讨论】:

  • 说真的,您如何使用 Hibernate 和 JDO?

标签: hibernate gwt arraylist jdo


【解决方案1】:

解决了..由于将Route对象的busStops和busStopKeys列表从服务器发送到客户端而引发了异常..在将数据发送到客户端之前设置为null的列表解决了问题..我有另一种方法来检索与路线关联的巴士站列表。如果它是正确的方法,请不要这样做,但它解决了问题。现在将重写代码以使其成为正确的 JDO 代码。感谢所有提供他们的人是时候为我的问题提出解决方案了..

【讨论】:

    【解决方案2】:

    添加

    datanucleus-core-1.1.0.jar
    

    到你的类路径。然后再试一次

    下载地址: http://www.docjar.com/jar_detail/datanucleus-core-1.1.0.jar.html

    【讨论】:

    • 我的 Eclipse 项目中的 App Engine SDK [App Engine 1.3.5] 库下确实有 datanucleus-core-1.1.5.jar。我需要将它单独添加到我的类路径中,还是应该专门添加到 datanucleus-core-1.1.0.jar 中?如果我问了一个非常愚蠢的问题,我很抱歉..
    【解决方案3】:

    我认为您不需要 Hibernate。 Datanucleus 是 GAE 使用的数据库提供程序,它应该与 JDO 一起工作。

    【讨论】:

    • 我参考了 www.gwtapps.com 中的 DatabaseEditor 示例。我认为我最好在 JDO 中编写所有内容。唯一困扰我的是它与使用相比有何变化busstop 的 id 到 route 的 id .. 因为它是 m 使用字符串来存储 id .. 不要了解从服务器端获取的内部工作 n 在路由 n 不在 busstop 的情况下如何出现 ArrayList 序列化问题..
    猜你喜欢
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    • 2013-08-05
    • 1970-01-01
    相关资源
    最近更新 更多