我是GAE,GWT,Hibernate和JDO的新手。我有Bus
,BusStop
和Route
類如下這是連載:com.google.gwt.user.client.rpc.SerializationException
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;
}
}
路線。 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>
在這裏,路線和公共汽車站有多對多的關係,每輛公共汽車都有一條路線。 我只是存儲巴士路線的編號,但隨後,在獲取總線對象, 它提供了以下錯誤
com.google.gwt.user.client.rpc.SerializationException:類型'org.datanucleus.sco.backed.ArrayList'未包含在可由此SerializationPolicy序列化的類型集合中,或者其Class對象無法加載。爲了安全起見,這種類型將不會被序列化:例如
儲存時不會有問題。現在我不直接處理Bus對象中的ArrayList。 所以我無法弄清楚在哪裏操縱datanucleus ArrayList對象到 util ArrayList。
此外,當我將busstop id存儲在總線表中而不是路由ID時,該程序正常工作。獲取總線對象後,我正在顯示其詳細信息。在這樣做的時候,我通過RouteDAO檢索路由對象的名稱字段。
請幫我...
認真編輯您的代碼。 – 2011-03-22 11:37:47
嚴重的是,你如何使用Hibernate和JDO? – DataNucleus 2011-03-22 11:45:44