I am developing an application that will run on both MySql and MS SQL.
I have a field that is "geometry" type for spatial.
By using:
@Column(columnDefinition = "geometry")
private Point geometry;
(point is org.springframework.data.geo.Point)
Hibernate creates the field properly (hbm2ddl).
But inserting any point does not work. I get : Data truncation: Cannot get geometry object from data you send to the GEOMETRY field
I use spring-boot-jpa-starter.. and not direct hibernate.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.2.2.Final</version>
</dependency>
Regards, Ido
Spring data jpa- it is same like jpa means we can describe in below way. Spring Data Jpa is jpa data abstraction access which means it likes a jpa but it add some extra functionality, Without jpa we can not implement the spring data jpa.
PagingAndSortingRepository provides methods to do pagination and sort records. JpaRepository provides JPA related methods such as flushing the persistence context and delete records in a batch.
Spring Data JDBC has less abstractions than Spring Data JPA, but uses Spring Data concepts to make it easier to do CRUD operations than Spring JDBC. It sits closer to the database because it does not contain the most part of the Spring Data magic when querying the database.
Spring Data JPA aims to significantly improve the implementation of data access layers by reducing the effort to the amount that's actually needed. As a developer you write your repository interfaces, including custom finder methods, and Spring will provide the implementation automatically.
Hello I have successfully mapped a point in JPA. Here's what I did:
I have this on Maven:
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.2.5.Final</version>
</dependency>
I have this on my entity:
@Column(name = "locationpoint", columnDefinition = "POINT")
private Point locationpoint;
I have this on my application.properties:
# needed for Location domain class
spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.mysql.MySQL56InnoDBSpatialDialect
I can get the value using this:
locationRepository.findOne((long) 1).getLocationpoint().getX();
locationRepository.findOne((long) 1).getLocationpoint().getY();
I based my solution from here Matti Tahvonen's example:
https://github.com/mstahv/spring-boot-spatial-example
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With