如何使请求工厂不可运输型可运输型



根据这个答案:com.vividsolutions.jts.geom.Geometry是否可以使用requestfactory直接传输?使用requestfactory,几何体是不可传输的(一种类型的特殊情况)。

那么这会奏效吗?:

@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 private Integer版本;错误已修复。

不仅可以工作,而且这是使其工作的(最简单)方法。

替代方案包括使用包装器/构建器。我也见过有人使用EntityProxy,其中字符串化的值被用作标识符,但要注意RequestFactory需要每个请求的缓存。

最新更新