0

这是我的设置:

  • PostgreSQL 9.3
  • 地理信息系统 2.1.4
  • 日食火星
  • 休眠工具 5.0
  • 休眠空间4.35.0

我还添加了postgis-jdbc.jarjts.jar构建路径。

.cfg.xml文件打开:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
    <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
    <property name="hibernate.connection.password">the_pass</property>
    <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/the_db</property>
    <property name="hibernate.connection.username">me</property>
    <property name="hibernate.default_schema">the_schema</property>
    <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
    <property name="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect"</property>
    <!-- "Import" the mapping resources here -->

在该reveng.xml文件中,包含几何类型字段的表使用table-filter元素显式声明:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
    [...]
    <table-filter match-name="coordinates"></table-filter>
    <table-filter match-name="polygon"></table-filter>
</hibernate-reverse-engineering>

Hibernate 代码生成配置正在为几何类型字段创建具有这种属性和方法的 POJO:

private Serializable geom;

public Serializable getGeom() {
        return this.geom;
}

public void setGeom(Serializable geom) {
        this.geom = geom;
}

Hibernate Spatial 教程中,几何字段映射到 JTS 类型,例如 ( com.vividsolutions.jts.geom.Point)。因此,使用此代码不可能遵循那里提出的机制来检索/更新空间字段。

是否可以以某种方式调整 Hibernate 配置以生成从空间字段到 JTS 类型的映射?Serializable还是必须改用这些生成的属性?

更新:Hibernate Spatial 邮件列表中的 Bakc我被告知我应该有匹配的 Hibernate Spatial 和 Hibernate 版本。官方网站上没有 Hibernate Spatial 5.0.7,但我在其他地方找到了它。即使使用这些匹配版本,我也会Serializable在生成的 POJO 中获取类型字段。

4

1 回答 1

1

您甚至可以在 hibernate.reveng.xml 中使用元标记来执行此操作,如下所示:

    <table name="position_vehicle" schema="public">
    <primary-key>
        <generator class="sequence">
            <param name="sequence">position_vehicle_id_seq</param>
        </generator>
        <key-column name="id"/>
    </primary-key>
    <column name="position">
        <meta attribute="use-in-tostring">true</meta>
        <meta attribute="property-type">com.vividsolutions.jts.geom.Geometry</meta>
    </column>
</table>

我正在使用休眠工具 5.0.0 和休眠空间 5.1.0。有关元标记的更多信息,请转到休眠元

于 2016-07-20T17:36:17.537 回答