application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5432/test_postgis spring.datasource.username=postgres spring.datasource.password=1234 spring.datasource.driver-class-name=org.postgresql.Driver spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.postgis.PostgisDialect spring.jpa.hibernate.ddl-auto=update dependencies:
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation group: 'org.hibernate.orm', name: 'hibernate-spatial', version: '6.5.0.Final' //dont know if its necessary nothing changes with or without implementation group: 'org.locationtech.jts', name: 'jts-core', version: '1.19.0' entity:
import org.locationtech.jts.geom.Polygon; import jakarta.persistence.*; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor @Entity @Table(name = "GEOM") public class Geom { @Id @Column(name = "ID_GEOM") @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @Column(name = "POLYG", columnDefinition = "geometry(Polygon,4326)") private Polygon polyg; } table:
CREATE TABLE geom ( id_geom SERIAL PRIMARY KEY, polyg GEOMETRY(POLYGON, 4326) ); Error on compilation:
org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.spatial.dialect.postgis.PostgisDialect] as strategy [org.hibernate.dialect.Dialect] Tried changing from org.hibernate.orm to the old org.hibernate, still got the same error
Tried removing the spring.jpa.properties.hibernate.dialec propertie, then it compiles and run, but when I try to request it it gives the following error:
[nio-8080-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Ignoring exception, response committed already: org.springframework.http.converter.HttpMessageNotWritableException Could not write JSON: Infinite recursion (StackOverflowError) [nio-8080-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError)] the response JSON:
[{"id":1,"polyg":{"envelope":{"envelope":{"envelope":{"envelope":..........}}}}}}}}} tried different JTS such as vividsolution jts, but it seens to be moved to jts-core
tried different and older versions of hibernate spatial tried even the PgPolygon
nothing seens to work
edit: already tried everything found on: