我是GAE,GWT,Hibernate和JDO的新手。我有Bus
,BusStop
和Route
类,序列化如下:
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映射:
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序列化的类型集中,或者其Class对象无法加载。出于安全考虑,此类型不会被序列化:实例
存储它时没有问题。现在我没有直接处理Bus对象中的ArrayList。 所以我无法弄清楚在哪里操纵datanucleus ArrayList对象 util ArrayList。
此外,当我将busstop id存储在总线表中而不是路由id时,程序运行正常。获取总线对象后,我正在显示其详细信息。在这样做时,我通过RouteDAO检索路由对象的名称字段。
请帮帮我......
答案 0 :(得分:1)
解决了..由于将Route对象的busStops和busStopKeys列表从服务器发送到客户端,异常已经上升。在将数据发送到客户端之前设置为null的列表解决了问题。我有另一种方法来检索与路由相关的公交车站列表.. Donno如果它是正确的方式,但它解决了问题..现在将重写代码使其成为一个正确的JDO代码.. Thanx给所有给他们的人是时候建议解决我的问题..
答案 1 :(得分:0)
添加
datanucleus-core-1.1.0.jar
到你的类路径。然后再试一次
下载网址: http://www.docjar.com/jar_detail/datanucleus-core-1.1.0.jar.html
答案 2 :(得分:0)
我认为你不需要Hibernate。 Datanucleus是GAE使用的数据库提供者,它将与JDO一起工作。