【问题标题】:How to make a request factory non-transportable type transportable?如何使请求工厂不可移动类型可移动?
【发布时间】:2013-07-01 23:28:36
【问题描述】:

根据这个答案:Is com.vividsolutions.jts.geom.Geometry directly transportable using requestfactory? Geometry 是(一种类型的特殊情况)不可使用 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 版本;错误已修复。

【问题讨论】:

    标签: gwt gis geospatial requestfactory hibernate-spatial


    【解决方案1】:

    它不仅会起作用,而且是使它起作用的(最简单的)方法。

    替代方案涉及使用包装器/构建器。我还看到有人使用EntityProxys,其中字符串化的值用作标识符,但要注意RequestFactory requires a per-request cache

    【讨论】:

    • 我的方法会被认为是不好的做法,而不是说使用包装器(你说这是最简单的方法而不是最好的方法)?
    • 我不认为有任何“最好”的方式。如果您需要处理它有一个对象,那么拥有一个 String 类型的字段并可能在运行中(可能缓存)构建一个 Geometry 怎么样? (“最好”的方法可能是避免进行不必要的转换)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-27
    • 1970-01-01
    相关资源
    最近更新 更多