在弹簧引导项目,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制作..所以我能接受这个奇怪的东西,可能是它构成了查询的“错误'的方式,也许它是连接到我看到的价值,当我做出选择...
任何想法?