【发布时间】:2017-06-22 01:05:36
【问题描述】:
我正在开展一个项目,我将在其中检索用户的纬度和经度。由此,我想将它作为一个点存储到数据库中。但是,当我尝试这样做时,我遇到了以下错误:o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: Invalid endian flag value encountered.
我正在采用暴露给客户端的模型并将其映射如下:
public static Point createPoint(double longitude, double latitude){
GeometryFactory gf = new GeometryFactory();
Coordinate coord = new Coordinate(longitude, latitude );
Point point = gf.createPoint( coord );
return point;
}
所以我会粗略地调用这个方法来将值映射为一个点:
createPoint(user.getLocation().getLongitude(), user.getLocation().getLatitude());
然后我会将返回的值存储到数据库中。
我的 pom 文件有以下依赖:
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.2.4.Final</version>
<exclusions>
<exclusion>
<artifactId>postgresql</artifactId>
<groupId>postgresql</groupId>
</exclusion>
</exclusions>
</dependency>
jpa 配置:
jpa:
database: POSTGRESQL
open-in-view: false
show-sql: true
hibernate:
ddl-auto: none
dialect: org.hibernate.spatial.dialect.postgis.PostgisDialect
naming:
naming-strategy: org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy
列定义:
@Column(name="point")
private com.vividsolutions.jts.geom.Point point;
关于如何修复此错误的任何想法? 提前谢谢大家。
【问题讨论】:
-
不确定是否理解您的正确,但不是
javax.persistence.AttributeConverter您在寻找什么?
标签: java spring hibernate postgis spatial