Hibernate 5.0.1 将 PostGIS 数据存储为字节而不是空间类型

Hibernate 5.0.1 with PostGIS data stored as bytes instead of spatial types

我正在尝试使用以下技术组合设置一个新项目

实体。我发现 org.hibernate.spatial.GeometryType 已被删除,现在似乎已移至 geo-latte-1 中的 org.geolatte.geom.GeometryType。0.jar

@Entity
@Table(name = "AREA")
@NamedQueries(@NamedQuery(name = "findAllAreas", query = "SELECT t FROM Area t"))
public class Area {
    private long id;
    private String info;
    private Geometry location;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    @Column(name = "INFO")
    public String getInfo() {
        return info;
    }
    public void setInfo(String info) {
        this.info = info;
    }
    @Column(name = "POLYGON")
    @Type(type = "org.geolatte.geom.GeometryType")
    public Geometry getLocation() {
        return location;
    }
    public void setLocation(Geometry location) {
        this.location = location;
    }

}

Spring 设置

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan">
        <array>
            <value>org.example.entity</value>
        </array>
    </property>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    </property>
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.dialect">org.hibernate.spatial.dialect.postgis.PostgisDialect
            </prop>
        </props>
    </property>
</bean>

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.postgresql.Driver" />
    <property name="url" value="jdbc:postgresql://localhost:5432/sadb" />
    <property name="username" value="username" />
    <property name="password" value="password" />
</bean>

数据库设置

结果

我能够毫无问题地保留和检索区域实体。但是列上的类型似乎是字节数据,而不是 PostGIS 空间类型。知道我做错了什么吗?

sadb=> \d+ area;
                                 Table "public.area"
 Column  |          Type          | Modifiers | Storage  | Stats target | Description
---------+------------------------+-----------+----------+--------------+------------
 id      | bigint                 | not null  | plain    |              |
 info    | character varying(255) |           | extended |              |
 polygon | bytea                  |           | extended |              |

使用 Hibernate 5+,您不需要 @Type 注释。包括它似乎会导致我看到的错误。删除它可以解决问题。多边形列如何具有 PostGIS 类型的几何图形。