Hibernate persist failure with PostGIS Geometry

前端 未结 3 1753
长情又很酷
长情又很酷 2020-12-31 19:07

Related to previous question. I have a Spring Roo application using Hibernate to write a Geometry object to a PostGIS database using JTS. I believe I\'ve fixed the problems

3条回答
  •  一个人的身影
    2020-12-31 19:41

    Yes, the ? are substituted by the values you need to store.

    Did you try to use the following type: GeometryUserType and not the GeometryType? I suspect GeometryType is not directly supported by the API of Hibernate Spatial Project. It is maybe an abstract class which you could not instantiate directly to map your datas with annotations - it acts beyond the scene as we have experimented.

    Caused by: java.lang.UnsupportedOperationException which has make me tell that.

    And the last XML stuff inside the tutorial you have followed is clear:

    ...
    
        
    
    ...
    

    Looking at the code inside the GeometryUserType I see only one place where these exception could be thrown.

    public Object conv2DBGeometry(Geometry jtsGeom, Connection connection) {
            org.postgis.Geometry geom = null;
            jtsGeom = forceEmptyToGeometryCollection(jtsGeom);
            if (jtsGeom instanceof com.vividsolutions.jts.geom.Point) {
                geom = convertJTSPoint((com.vividsolutions.jts.geom.Point) jtsGeom);
            } else if (jtsGeom instanceof com.vividsolutions.jts.geom.LineString) {
                geom = convertJTSLineString((com.vividsolutions.jts.geom.LineString) jtsGeom);
            } else if (jtsGeom instanceof com.vividsolutions.jts.geom.MultiLineString) {
                geom = convertJTSMultiLineString((com.vividsolutions.jts.geom.MultiLineString) jtsGeom);
            } else if (jtsGeom instanceof com.vividsolutions.jts.geom.Polygon) {
                geom = convertJTSPolygon((com.vividsolutions.jts.geom.Polygon) jtsGeom);
            } else if (jtsGeom instanceof com.vividsolutions.jts.geom.MultiPoint) {
                geom = convertJTSMultiPoint((com.vividsolutions.jts.geom.MultiPoint) jtsGeom);
            } else if (jtsGeom instanceof com.vividsolutions.jts.geom.MultiPolygon) {
                geom = convertJTSMultiPolygon((com.vividsolutions.jts.geom.MultiPolygon) jtsGeom);
            } else if (jtsGeom instanceof com.vividsolutions.jts.geom.GeometryCollection) {
                geom = convertJTSGeometryCollection((com.vividsolutions.jts.geom.GeometryCollection) jtsGeom);
            }
    
            if (geom != null)
                return new PGgeometry(geom);
            else
                throw new UnsupportedOperationException("Conversion of "
                        + jtsGeom.getClass().getSimpleName()
                        + " to PGgeometry not supported");
        }
    

    Where PGgeometry stands for PostGis Geometry I think (or maybe PostgreSQL).

    I have found some topics where Karel Maesen and others speak about the InnoDB support is not very well, but they are maybe outdated (05-2011).

    Good luck!

提交回复
热议问题