Gwt 如何使请求工厂不可传输类型可传输?
根据这个答案:几何体(一种类型的特殊情况)不可使用requestfactory进行传输 那么这会起作用吗Gwt 如何使请求工厂不可传输类型可传输?,gwt,gis,geospatial,requestfactory,hibernate-spatial,Gwt,Gis,Geospatial,Requestfactory,Hibernate Spatial,根据这个答案:几何体(一种类型的特殊情况)不可使用requestfactory进行传输 那么这会起作用吗 @Entity public class Poi { @GeneratedValue(strategy=GenerationType.IDENTITY) @Id private Integer id; @Type(type="org.hibernate.spatial.GeometryType") private Geometry geom;
@Entity
public class Poi {
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Id
private Integer id;
@Type(type="org.hibernate.spatial.GeometryType")
private Geometry geom;
//bi-directional many-to-one association to PoiCateg
@ManyToOne
@JoinColumn(name="id_cat")
private PoiCateg poiCateg;
@Version
private Integer version;
public Poi() {
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public Geometry getGeom() {
return this.geom;
}
public void setGeom(Geometry geom) {
this.geom = geom;
}
public PoiCateg getPoiCateg() {
return this.poiCateg;
}
public void setPoiCateg(PoiCateg poiCateg) {
this.poiCateg = poiCateg;
}
//not your standard getters and setters
public String getGeomClient() {
return //result of method that converts from Geometry object to WKT string representation
}
public void setGeomClient(String geom) {
this.geom = // result of method that converts from String to Geometry
}
}
然后,我修改的Poi实体代理如下所示:
@ProxyFor(value=Poi.class)
public interface PoiProxy implements EntityProxy {
public Integer getId() ;
public void setId(Integer id);
public PoiCategEntityProxy getPoiCateg() ;
public void setPoiCateg(PoiCateg poiCateg);
//not your standard getters and setters
public String getGeomClient() ;
public void setGeomClient(String geom) ;
}
由于服务器实体中的getGeomClient和setGeomClient包含几何体类型,因此客户端上会出现问题吗
EDIT1:忘记@Version私有整数版本;错误已修复。不仅它可以工作,而且这是使它工作的(最简单)方法
替代方案包括使用包装器/构建器。我也见过有人使用
EntityProxy
s,其中字符串化的值被用作标识符,但请注意。我的方法会被认为是错误的做法,而不是说使用包装器(你说这是最简单的而不是最好的方法)?我不认为有任何“最佳”方法。如果您需要处理一个字符串类型的字段,并且该字段中有一个对象,那么可以动态地(可能是缓存的)构建一个几何体?(最好的方法可能是避免进行不必要的转换)