2017-08-28 76 views
4

在彈簧引導項目,Java8,具有休眠空間和PostgresDB 9.4休眠空間POSTGIS PSQLException列的類型的點,但表達的類型爲BYTEA

<dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-spatial</artifactId> 
     <version>5.2.10.Final</version> 
    </dependency> 

application.properties

spring.datasource.driver-class-name=org.postgresql.Driver 
spring.jpa.database-platform=org.hibernate.spatial.dialect.postgis.PostgisPG94Dialect 
spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.postgis.PostgisPG94Dialect 

(我也試過PostgisPG9Dialect)

我的實體有一個屬性

... 
import com.vividsolutions.jts.geom.Point; 
.... 
@Column(columnDefinition = "Point") 
private Point cityLocation; 

如果我保存空值,這是確定的,但如果我把一個價值

setCityLocation(new GeometryFactory().createPoint(new Coordinate(lng, lat)); 

我:

PSQLException: ERROR: column "city_location" is of type point but expression is of type bytea You will need to rewrite or cast the expression. 

在我的數據庫,我可以看到列定義爲

type: point 
column size: 2147483647 
data type: 1111 
num prec radix:  10 
char octet length: 2147483647 

我正在瘋狂......爲什麼它不起作用?

UPDATE(它仍然不工作,我收集新信息)

1)我想這個問題可能是數據庫的創建。 在我application.properties我也有:

spring.jpa.properties.hibernate.hbm2ddl.auto=update 

這樣的模式會由Hibernate更新「自動」。

2)我可以成功,直接在數據庫(我用 「松鼠SQL」 作爲客戶端)

update my_table set city_location = POINT(-13,23) where id = 1 

運行一個查詢,如果我

select city_location from my_table where id = 1 

答案是

<Other> 

我看不到值...我在點類型內有空值的記錄得到相同的答案...

3)設定的值到「點」列後與查詢,我沒有更多的可以從表中讀取,我收到異常:

org.geolatte.geom.codec.WktDecodeException : Wrong symbol at position: 1 in Wkt: (-13.0,23.0) 

4)我往裏冬眠空間,5.2.10.Final.jar,我發現在包org.hibernate.spatial兩個「geolatte」命名類:

GeolatteGeometryJavaTypeDescriptor.class GeolatteGeometryType。類

5)並且(特定於Squirrel SQL客戶端專家): 如果我嘗試更改「my_table」(而不是'point'city_location中的任何一個列的值)列的值,錯誤一個類似於我在Java中recive當我嘗試插入點值:

Exception seen during check on DB. Exception was: 
ERROR: operator does not exist: point = character varying 
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. 

松鼠是用java製作..所以我能接受這個奇怪的東西,可能是它構成了查詢的「錯誤'的方式,也許它是連接到我看到的價值,當我做出選擇...

任何想法?

回答

3

我找到了解決方案!

需要修復代碼,我在另一個stackoverflow問題中讀到的一個魔術保存了我的生活。

的問題是,DB柱以錯誤的方式創建:

在分貝列類型

應該幾何

我刪除了columnDefinition =「點」從@Column批註和我跑的查詢

CREATE EXTENSION postgis; 

在我的分貝以下INSTR Postgis installation: type "geometry" does not exist

Krishna Sapkota你是我的新超級英雄!

相關問題