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?

2
  • 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? Commented May 3, 2016 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. Commented May 3, 2016 at 11:38

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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.
where does JTSGeometryType and PGGeometryTypeDescriptor come from?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.