简体   繁体   English

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

[英]hibernate-spatial-4.0 creates bytea column type instead of geometry

I am working with application which uses spring 3.1 and hibernate 4.2.我正在处理使用 spring 3.1 和 hibernate 4.2 的应用程序。 For spatial feature we are planning to use hibernate spatial with postgis.对于空间特征,我们计划将 hibernate spatial 与 postgis 结合使用。 But hibernate spatial creates column with bytea type instead of geometry.但是 hibernate spatial 使用 bytea 类型而不是几何创建列。 I am not able to find out where is root cause of this.我无法找出根本原因在哪里。 I spend already couple of days in resolving but not successful.我已经花了几天时间解决问题但没有成功。

hibernate-spatial-4.0.jar is used.使用 hibernate-spatial-4.0.jar。

I am using following hibernate.properties file我正在使用以下 hibernate.properties 文件

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

I am using following annotation in Entity我在实体中使用以下注释

    @Column(columnDefinition="Geometry", nullable = true)
        @Type(type = "org.hibernate.spatial.GeometryType")
        private Point geom;

Application successfully creates following table but instead of geometry type it creates bytea for column geom应用程序成功创建了下表,但它没有为几何类型创建列 geom 的 bytea

                         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)

However manually I am able to create Geometry type column in postgis2.2-postgres9.5 database但是手动我能够在 postgis2.2-postgres9.5 数据库中创建几何类型列

I went through almost every thread but unsuccessful.我几乎遍历了每个线程,但没有成功。 Need help.需要帮忙。

I could able to fix this issue by modifying annotations used in Entity class.我可以通过修改 Entity 类中使用的注释来解决这个问题。 This works for me.这对我有用。 @Column(columnDefinition="geometry(Point,4326)") private org.hibernate.spatial.GeometryType geom; @Column(columnDefinition="geometry(Point,4326)") private org.hibernate.spatial.GeometryType geom;

PostgisDialect registers JTS or Geolatte Point types (refer to the Hibernate spatial documentation and the sources . In case of JTS make sure you use an up to date version (org.locationtech.jts) rather than the old one (com.vividsolutions.jts) by updating your dependencies and checking your imports (I had both, the old and the new dependency on my classpath and accidently imported the wrong one). PostgisDialect 注册 JTS 或 Geolatte Point 类型(请参阅 Hibernate 空间文档来源。如果是 JTS,请确保使用最新版本 (org.locationtech.jts) 而不是旧版本 (com.vividsolutions.jts)通过更新您的依赖项并检查您的导入(我在我的类路径上同时拥有旧的和新的依赖项并且不小心导入了错误的依赖项)。

A working example (in Kotlin, but getting the Java imports / annotations should be straightforward):一个工作示例(在 Kotlin 中,但获取 Java 导入/注释应该很简单):

My entity (note: there is no annotation at all on the Point type:):我的实体(注意:Point 类型上根本没有注释:):

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
 )

The maping function to create the TrackPoint which is then persisted:用于创建 TrackPoint 然后被持久化的映射函数:

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())
}    

Additionally you might use one of the more recent postgis dialects (like PostgisPG95Dialect) since PostgisDialect is deprecated.此外,您可能会使用一种更新的 postgis 方言(如 PostgisPG95Dialect),因为 PostgisDialect 已被弃用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate空间中的JTS几何生成“错误:函数内(几何,bytea)不存在” - JTS geometry in Hibernate spatial generating " ERROR: function within(geometry, bytea) does not exist" 休眠空间错误:类型“几何”不存在 - hibernate spatial error: type “geometry” does not exist Hibernate Spatial 5.0.4.Final 和 PostgreSQL 几何列上的映射错误 - Mapping Error on Hibernate Spatial 5.0.4.Final and PostgreSQL geometry column PostgreSQL 使用 JPA 和 Hibernate 抛出“列的类型为 jsonb,但表达式的类型为 bytea” - PostgreSQL throws "column is of type jsonb but expression is of type bytea" with JPA and Hibernate Hibernate Spatial创建几何对象 - Hibernate Spatial Create Geometry object 休眠空间-尝试加载Oracle几何时引发UnsupportedOperationException - Hibernate Spatial - Throws UnsupportedOperationException trying to load Oracle geometry 无法使用休眠空间将几何对象持久保存到oracle - failing to persist geometry object to oracle using hibernate spatial 如何获取带有 bytea 类型 id 列的表? - How to fetch table with bytea type id column? 如何使用休眠会话将oracle空间SDO_GEOMETRY转换为com.vividsolutions.jts.geom.Geometry - how to fectch oracle spatial SDO_GEOMETRY as com.vividsolutions.jts.geom.Geometry using hibernate session 无法从发送到 GEOMETRY 字段的数据中获取几何对象:Hibernate Spatial + Mysql - Cannot get geometry object from data you send to the GEOMETRY field : Hibernate Spatial + Mysql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM