【发布时间】:2019-09-12 13:48:06
【问题描述】:
使用 spring boot jpa 将经度和纬度存储为 Postgres 中的点作为几何位置。
应用下面的代码后,它会抛出:列“位置”是点类型,但表达式是字节类型。
在获取数据时也会抛出: 无法反序列化;嵌套异常是 org.hibernate.type.SerializationException: could not deserialize
在 pom.xml 中添加依赖
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.4.1.Final</version>
</dependency>
在实体类中添加列。
@Column(columnDefinition = "POINT")
private Point location;
用于将数据存储到数据库中
GeometryFactory geometryFactory = new GeometryFactory();
Coordinate coordinate = new Coordinate();
coordinate.x = 2;
coordinate.y = 5;
Point myPoint = geometryFactory.createPoint(coordinate);
user.setLocation(myPoint);
我需要在 Postgres 中以 (30.5,53.123) 格式存储数据。
【问题讨论】:
标签: postgresql spring-boot spring-data-jpa