-1

I am using Spring Boot for a project I'm working on using spatial data. For the spatial data I'm using Hibernate Spatial. This is the configuration for my entity:

@Column(name="LOCATION",columnDefinition="geometry(Point,4326)")
private Point location;

Where Point is of the class com.vividsolutions.jts.geom.Point. This also includes a getter and setter.

When retrieving this entity with a normal repository.findOne("id") this also includes the location in my result, mapped to a Point. However, I need to have some dynamic query system later on in the system. So therefore I also query data with a class that inherits from org.springframework.data.jpa.domain.Specification. When using this specification, the location is always null. The SQL debug information shows me that the location is retrieved from the database, but for some reason, this is not mapped to my entity object.

My spring-boot version is 1.4.0.RELEASE. The data is coming from a mysql database.

Any help to retrieve geometry data with the use of a Specification will be greatly appreciated.

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
Cerebres
  • 343
  • 3
  • 16

1 Answers1

0

I tested same with Mysql Spatial and retrieving the data by applying query using Specifications. I could retrieve the spatial data.

Here are the few Pointers you can try with.

  1. Make sure you've set the dialect which supports Spatial Query and types.

    spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.mysql.MySQL56InnoDBSpatialDialect

  2. No need to define Column definition.

Remove columnDefinition="geometry(Point,4326)

Karthik Prasad
  • 9,662
  • 10
  • 64
  • 112
  • Thank you for your answer. Unfortunatly this does not help. I think that the problem lies within org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor. I do not see an attribute for any geometry type within my generated models. Did I forget something in my plugin definition? I am using maven. – Cerebres Mar 02 '17 at 12:38
  • When I change my definition from Point to Geometry, it gets added to the metamodel, but the value stays null. – Cerebres Mar 02 '17 at 12:56
  • @Cerebres BTW which version of spring-boot and hibernate you are using. I tested with spring-boot 2.0.0 snapshot and hibernate 5.2.5 – Karthik Prasad Mar 02 '17 at 13:13
  • I am using: Spring boot 1.4.0.RELEASE Hibernate-spatial 5.2.2.Final – Cerebres Mar 02 '17 at 13:34
  • Ok, can you post the Dialect you are using? – Karthik Prasad Mar 02 '17 at 17:25
  • I'm using spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.mysql.MySQL5InnoDBSpatialDialect – Cerebres Mar 03 '17 at 08:25
  • 1
    Please use org.hibernate.spatial.dialect.mysql.MySQLSpatialDialect. it is the mostly the culprit. I previously used org.hibernate.spatia‌​l.dialect.mysql.MySQ‌​L56InnoDBSpatialDiale‌​ct, it was giving me error. – Karthik Prasad Mar 03 '17 at 10:26
  • Thank you for your assistance. Unfortunately changing the dialect is not really an option for me. – Cerebres Mar 03 '17 at 11:53
  • Hmm......... In that case you can use Point from org.geolatte.geom.Point as an alternative. – Karthik Prasad Mar 03 '17 at 12:05