有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我在postgres 9.4-1204-jdbc4中定义了此列

位置几何图形(点,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中时,它总是返回错误:

错误:遇到无效的endian标志值

我这样定义了hibernate方言

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

问题出在哪里


共 (0) 个答案