首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >hibernate-spatial 4.0创建bytea列类型而不是几何图形

hibernate-spatial 4.0创建bytea列类型而不是几何图形
EN

Stack Overflow用户
提问于 2016-01-13 16:23:38
回答 2查看 1.2K关注 0票数 1

我正在使用使用spring 3.1和hibernate 4.2的应用程序。对于空间特性,我们计划在postgis中使用hibernate spatial。但是hibernate spatial创建的列是bytea类型的,而不是几何类型的。我不能找出这个问题的根本原因。我已经花了几天的时间来解决问题,但没有成功。

使用hibernate-spatial 4.0.jar。

我正在使用下面的hibernate.properties文件

代码语言:javascript
复制
database.driverClassName=org.postgresql.Driver
database.url=jdbc:postgresql://127.0.0.1:5433/mpdb
database.username=postgres 
database.password=postgres 
hibernate.dialect=org.hibernate.spatial.dialect.postgis.PostgisDialect 
hibernate.show_sql=true 
hibernate.hbm2ddl.auto=update

我在实体中使用了以下注释

代码语言:javascript
复制
    @Column(columnDefinition="Geometry", nullable = true)
        @Type(type = "org.hibernate.spatial.GeometryType")
        private Point geom;

应用程序成功创建了以下表,但它为列geom创建了bytea,而不是几何类型

代码语言:javascript
复制
                         Table "public.tile"
           Column           |            Type             | Modifiers
----------------------------+-----------------------------+-----------
 id                         | integer                     | not null
 alt                        | double precision            | not null
 geom                       | bytea                       |
 lat                        | double precision            | not null
 lng                        | double precision            | not null
 multipath_table            | text                        | not null
 multipath_table_min_value  | double precision            |
 multipath_table_resolution | integer                     |
 multipath_table_tx_id      | text                        |
 tile_created               | timestamp without time zone | not null
 tile_data_age              | integer                     |
 tile_data_present          | text                        | not null
 tile_num_tx                | integer                     |
Indexes:
    "tile_pkey" PRIMARY KEY, btree (id)

但是,我可以手动在postgis2.2-postgres9.5数据库中创建几何类型列

我几乎遍历了每一个线程,但都没有成功。需要帮助。

EN

回答 2

Stack Overflow用户

发布于 2016-01-14 13:19:58

我可以通过修改Entity类中使用的注释来解决这个问题。这对我很有效。@Column(columnDefinition="geometry(Point,4326)")私有org.hibernate.spatial.GeometryType geom;

票数 2
EN

Stack Overflow用户

发布于 2020-03-01 05:46:22

PostgisDialect注册JTS或Geolatte Point类型(请参阅Hibernate空间documentationsources。在JTS的情况下,通过更新您的dependencies并检查您的导入,确保您使用的是最新版本(org.locationtech.jts)而不是旧版本(com.vividsolutions.jts) (我在我的类路径上有两个依赖项,旧的和新的依赖项,并且意外地导入了错误的依赖项)。

一个工作示例(在Kotlin中,但获取Java导入/注释应该很简单):

我的实体(注意: Point类型上根本没有注释!):

代码语言:javascript
复制
import org.locationtech.jts.geom.Point
import java.time.ZonedDateTime
import javax.persistence.*

@Entity
data class TrackPoint(
        @Id @GeneratedValue var id: Long? = null,
        var location : Point,
        var time : ZonedDateTime,
        @ManyToOne
        var track: Track? = null
 )

用于创建TrackPoint的映射函数,然后将其持久化:

代码语言:javascript
复制
fun mapWayPoint2TrackPoint(it: WayPoint) : TrackPoint {
    val coordinate = Coordinate(it.longitude.toDouble(), it.latitude.toDouble(), it.elevation.get().toDouble())
    val point = geometryFactory.createPoint(coordinate)
    return TrackPoint(location = point, time = it.time.get())
}    

此外,您可以使用较新的postgis方言之一(如PostgisPG95Dialect),因为PostgisDialect已被弃用。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34761606

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档