【发布时间】:2015-02-21 20:46:42
【问题描述】:
在我的 PostgreSQL 9.3 + PostGIS 2.1.5 中,我有一个表 PLACE,其中有一列 coordinates 类型为 Geometry(Point,26910)。
我想将它映射到我的 Spring Boot 1.1.9 Web 应用程序中的 Place 实体,该应用程序使用 Hibernate 4.0.0 + 。 Place 可用于 REST 存储库。
不幸的是,当我GET http://localhost:8080/mywebapp/places 收到这个奇怪的 JSON 响应:
{
"_embedded" : {
"venues" : [ {
"id" : 1,
"coordinates" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
"envelope" : {
等等不确定...!春季日志没有帮助..
我正在使用这个 application.properties:
spring.jpa.database-platform=org.hibernate.spatial.dialect.postgis.PostgisDialect
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:postgresql://192.168.1.123/mywebapp
spring.datasource.username=postgres
spring.datasource.password=mypwd
spring.datasource.driverClassName=org.postgresql.Driver
首先,用database-platform代替database可以吗?
也许我必须使用以下设置而不是上述设置?
spring.datasource.url=jdbc:postgresql_postGIS://192.168.1.123/mywebapp
spring.datasource.driverClassName=org.postgis.DriverWrapper
反正我的实体是这样的:
@Entity
public class Place {
@Id
public int id;
@Column(columnDefinition="Geometry")
@Type(type="org.hibernate.spatial.GeometryType") //"org.hibernatespatial.GeometryUserType" seems to be for older versions of Hibernate Spatial
public com.vividsolutions.jts.geom.Point coordinates;
}
我的 pom.xml 包含这个相关部分:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1102-jdbc41</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>4.3</version><!-- compatible with Hibernate 4.3.x -->
<exclusions>
<exclusion>
<artifactId>postgresql</artifactId>
<groupId>postgresql</groupId>
</exclusion>
</exclusions>
</dependency>
有点奇怪的配置,我在网上找到的,目前最好用的一个。
我希望有人能帮助我解开这个谜团。 :)
【问题讨论】:
标签: spring hibernate postgresql spring-boot postgis