这是我的设置:
- PostgreSQL 9.3
- 地理信息系统 2.1.4
- 日食火星
- 休眠工具 5.0
- 休眠空间
4.35.0
我还添加了postgis-jdbc.jar
和jts.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 中获取类型字段。