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

I am trying to set up a new project with the following combination of technologies

  • Sleep + Spatial 5.0.1
  • PostgreSQL 9.4 with PostGIS 2.1.8
  • Spring 4.2.1
  • JTS 1.13

Entity I found that it was org.hibernate.spatial.GeometryTypedeleted and now it moves to org.geolatte.geom.GeometryTypein geo-latte-1.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 customization

<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>

Database setup

  • ZIP version for Windows
  • Copied to a PostGIS installation
  • the new PostGIS database and created all the extensions postgis, postgis_topology, fuzzystrmatch, postgis_tiger_geocoder

Result

I can save and retrieve area objects without problems. However, the column type is apparently byte data, not the PostGIS spatial type. Any ideas what I'm doing wrong?

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 |              |
+4
1

Hibernate 5+ @Type. , , , . . PostGIS.

+5

Source: https://habr.com/ru/post/1607981/


All Articles