Question

According to this answer: Is com.vividsolutions.jts.geom.Geometry directly transportable using requestfactory? Geometry is ( a particular case of a type that is ) non- transportable using requestfactory.

So then would this work? :

@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
    }
}

and then my modified entity proxy for Poi would look like:

@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) ;
}

since getGeomClient and setGeomClient in the server entity contain a geometry type will it be a problem on the client?

EDIT1: forgot about @Version private Integer version; mistake fixed.

Was it helpful?

Solution

Not only it'll work but that's the (simplest) way to make it work.

Alternatives involve using wrappers/builders. I've also seen people using EntityProxys where the stringified value is used as the identifier, but beware that RequestFactory requires a per-request cache.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top