Spring Java JPA: Using specification with hibernate spatial

1.6k views Asked by At

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.

1

There are 1 answers

9
Karthik Prasad On

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)