suchitra nair
suchitra nair

Reputation: 555

com.google.gwt.user.client.rpc.SerializationException

I am new to GAE, GWT, Hibernate and JDO. I have Bus, BusStop and Route classes which are serialized as follows:

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;
    }   
}

Hibernate mappings:

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>

Here, routes and bus stops have a many to many relationship, and every bus has a route. I am just storing the id of the route in bus, but then, while retrieving the bus object, it gives the following error

com.google.gwt.user.client.rpc.SerializationException: Type 'org.datanucleus.sco.backed.ArrayList' 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

While storing it doesn't have a problem. Now I am not dealing directly with ArrayList in Bus object. So I'm not able to figure out where to manipulate the datanucleus ArrayList object to util ArrayList.

Moreover, when I'm storing the busstop id in the bus table instead of route id, the program works fine. After fetching the bus object, I'm displaying its details. While doing so, I retrieve the route object's name field through the RouteDAO.

Please help me out ...

Upvotes: 0

Views: 1879

Answers (3)

suchitra nair
suchitra nair

Reputation: 555

Solved it.. The exception had risen due to sending of the busStops and busStopKeys lists of the Route object from the server to the client.. The lists when set to null before sending the data to the client solved the problem.. I have another method for retrieving the bus stop list associated with a route.. Donno if its a right way, but it solved the problem.. Will now rewrite the code to make it a proper JDO code.. Thanx to all who gave their time to suggesting a solution to my issue..

Upvotes: 1

kostas trichas
kostas trichas

Reputation: 3013

I think you don't need Hibernate. Datanucleus is the database provider GAE uses and it shall do the work with JDO.

Upvotes: 0

Hardik Mishra
Hardik Mishra

Reputation: 14877

Add

datanucleus-core-1.1.0.jar

to your classpath. Then try it again

URL for download: http://www.docjar.com/jar_detail/datanucleus-core-1.1.0.jar.html

Upvotes: 0

Related Questions