I have a problem to set latitude and longitude to Point with the usager of Hibanate Spatial feature in Spring Boot.
I cannot set it as I guess there is a problem in columnDefinition.
How can I fix it?
Here is the relevant part of the Entity class shown below
@Column(name = "POINT", columnDefinition = "geometry(Point,4326)")
private Point point;
public void setPoint(double latitude, double longitude) {
Coordinate coordinate = new Coordinate(latitude, longitude);
GeometryFactory geometryFactory = new GeometryFactory();
this.point = geometryFactory.createPoint(coordinate);
}
Here is the database configuration part of application.yml
spring:
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
format_sql: true
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
You don't need to specify column definition.Specifying the datatype as Point in your entity model is enough.
Please use the standard setter for the point field and use a utility function to calculate point using the coordinates.
Refer the answer below Use PostGIS geography point with hibernate spatial 5 in spring boot