【问题标题】:hibernate-spatial-4.0 creates bytea column type instead of geometryhibernate-spatial-4.0 创建 bytea 列类型而不是几何
【发布时间】:2016-01-13 08:23:37
【问题描述】:

我正在使用使用 spring 3.1 和 hibernate 4.2 的应用程序。对于空间特征,我们计划使用带有 postgis 的休眠空间。但是休眠空间会创建具有 bytea 类型而不是几何形状的列。我无法找出造成这种情况的根本原因在哪里。我已经花了几天时间解决但没有成功。

使用hibernate-spatial-4.0.jar。

我正在使用以下 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

我在实体中使用以下注释

    @Column(columnDefinition="Geometry", nullable = true)
        @Type(type = "org.hibernate.spatial.GeometryType")
        private Point 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)

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

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

【问题讨论】:

    标签: java spring hibernate


    【解决方案1】:

    我可以通过修改实体类中使用的注释来解决这个问题。 这对我有用。 @Column(columnDefinition="几何(点,4326)") private org.hibernate.spatial.GeometryType geom;

    【讨论】:

      【解决方案2】:

      PostgisDialect 注册 JTS 或 Geolatte Point 类型(请参阅 Hibernate 空间 documentationsources。 如果是 JTS,请确保您使用最新版本 (org.locationtech.jts) 而不是旧版本 (com.vividsolutions.jts),方法是更新您的 dependencies 并检查您的导入(我同时拥有旧版本和对我的类路径的新依赖并意外导入了错误的依赖项)。

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

      我的实体(注意: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
       )
      

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

      此外,由于不推荐使用 PostgisDialect,因此您可能会使用一种较新的 postgis 方言(如 PostgisPG95Dialect)。

      【讨论】:

        猜你喜欢
        • 2013-01-09
        • 1970-01-01
        • 2013-12-20
        • 2018-01-30
        • 1970-01-01
        • 2016-03-04
        • 1970-01-01
        • 1970-01-01
        • 2015-04-24
        相关资源
        最近更新 更多