0

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

1 Answer 1

0

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

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

8 Comments

I want to specify its defination. Is ST_GeomFromText(Point, 4326) enough for definition? Can you help me solve the issue.
Specifying the definition is fine. In order to isolate the issue, try with no definition first. Also change setter for the point field to public void setPoint(Point point){ this.point=point}.
@Column(name = "POINT", columnDefinition = "ST_GeomFromText(Point, 4326)") private Point point; Is it right? Why don't I use geometry(Point,4326) in the Point. Can you explain it?
Which one is right? geometry(Point,4326) or ST_GeomFromText(Point, 4326)
geometry(Point,4326) does not rely on any specific PostGIS functions. So I would prefer that. Try changing the setter first. i.e public void setPoint(double latitude, double longitude) {} to public void setPoint(Point point) {this.point=point} and use a util method to calculate point and pass to setter. This should work.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.