从hibernate + java存储postgres geometry(point,4326)列

时间:2017-07-13 13:06:18

标签: java hibernate postgis

我在postgres 9.4-1204-jdbc4

中定义了此列

位置几何(Point,4326)

我有这个带有这些依赖项的pom.xml:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-spatial</artifactId>
   <version>4.3</version>
 </dependency>
 <dependency>
   <groupId>com.vividsolutions</groupId>
   <artifactId>jts</artifactId>
   <version>1.13</version>
</dependency>

我希望存储此类中存储的数据:

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;

@Column(columnDefinition = "geometry(Point,4326)",name="location")
private Point locationPoint;


public void updateLocation(String locationAsString) {
    this.location = locationAsString;
    int separatorPosition = location.indexOf(" ");
    double x_location = Double.parseDouble(location.substring(0,separatorPosition));
    double y_location = Double.parseDouble(location.substring(separatorPosition));
    //this.locationPoint = new Point(x_location, y_location);
     Coordinate coord = new Coordinate(x_location, y_location );


     GeometryFactory gf = new GeometryFactory();
     this.locationPoint= gf.createPoint( coord );
     this.locationPoint.setSRID(4326);
}

但是当我尝试将对象存储在db中时,它总是返回错误:

错误:遇到无效的字节序标志值。

我已经用这种方式定义了hibernate方言

spring.jpa.properties.hibernate.dialect =org.hibernate.spatial.dialect.postgis.PostgisDialect

哪里可能是问题?

0 个答案:

没有答案