10

Documentation for hibernate 5.1 spatial is not yet released (AFAIK) and I'm trying to persist entities with JST geometries fields to PostgreSQL 9.5 + Postgis 2.2, without any luck.

I've also noticed that there is no org.hibernate.spatial package in hibernate-core-5.1.0. I've tried variations of the following annotation:

@javax.persistence.Column(name = "the_geom", columnDefinition = "Geometry")
public com.vividsolutions.jts.geom.Geometry geom;

When columnDefinition is set to "Point" I get "column "the_geom" is of type point but expression is of type bytea". In hibernate spatial 4 documentation it is said that the @Type annotation would not be needed from releases 5+, but what should be used instead? How to store the geom as a valid Postgis geometry?

Mihai Serban
  • 406
  • 2
  • 7
  • 18
  • Hi @Mihai I've the same issue right now with the same configuration and dependencies. I search for a while without any result, did you spot anything that drive at least what is the cause of the issue? – Dario May 03 '16 at 10:34
  • Hi @Dario, due to the lack of time I downgraded to hibernate 4.3 for the moment. I'm waiting for the official documentation to be available. – Mihai Serban May 03 '16 at 11:38

1 Answers1

0

After searching for a while I found a solution that fits my needs (I'm hoping also yours). Due to the fact that with version 5 all the jts and geolatte geometry types are capable of been managed directly by hibernate you should configure hibernate to manage those types.

In my scenario I manage all the configuration in a spring @Configuration class: there, as shown in the "example 9" of here I decided to use the MetadataBuilder approach as follows:

@Bean
public static MetadataBuilder metadataBuilder() {

    ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build();
    MetadataSources sources = new MetadataSources( standardRegistry );
    return sources.getMetadataBuilder();
}

@Bean
public static MetadataBuilder spatialConfiguration() {

    JTSGeometryType jtsGeometryType = new JTSGeometryType(PGGeometryTypeDescriptor.INSTANCE);
    return PersistenceConfiguration.metadataBuilder().applyBasicType(jtsGeometryType);
}

In this way all my jts geometries (there is also the other for geolatte geometries org.hibernate.spatial.GeolatteGeometryType) are mapped correctly as declare in my database model.

Hopes this can help you,

Dario.

Dario
  • 5,203
  • 1
  • 23
  • 26
  • I decided to stick with hibernate 4.3 for the moment, and I haven't tested your solution yet. I will migrate to 5.* sometime in the near future and validate this/accept answer. Thanks. – Mihai Serban Jun 15 '16 at 07:10
  • WIth 5.2.3.Final version of hibernate jts geometries are supported by default, without the need for extra configuration. I'm using JTS 1.13 version. – Mihai Serban Apr 14 '17 at 08:18
  • where does JTSGeometryType and PGGeometryTypeDescriptor come from? – lemario Jul 27 '23 at 13:27