1

I am trying to add a Point to a Postgres database and hibernate is not recognizing the Point type.

Entity:

@Table(name = "test_locations")
public class TestLoc {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    //@Column(columnDefinition = "geometry(Point, 4326)")
    //@Column(columnDefinition = "Geometry", nullable = true)
    //@Type(type = "org.hibernate.spatial.GeometryType")
    //@Column(columnDefinition = "geometry(Point, 4326)")
    //@Column(columnDefinition = "Point")
    //@Type(type = "jts_geometry")

    private Point geom;
}

Saving in service:

locationRepository.save(location);

The query comes out as:

insert into test_locations (geom) values (?)
binding parameter [1] as [VARBINARY] - [POINT (38.743494 -9.100922)]

And then I get the error:

SQL Error: 0, SQLState: XX000
ERROR: Invalid endian flag value encountered.

application.yml dialect:

jpa:
properties:
  hibernate:
    #dialect: org.hibernate.spatial.dialect.postgis.PostgisDialect  # Set the PostGIS dialect for Hibernate org.hibernate.spatial.dialect.postgis.PostgisDialect
    dialect: org.hibernate.dialect.PostgreSQL95Dialect  # Set the PostGIS dialect for Hibernate org.hibernate.spatial.dialect.postgis.PostgisDialect
    #dialect: org.hibernate.dialect.H2Dialect
    jdbc.lob.non_contextual_creation: true  # Set this to true if you encounter issues with large objects (LOBs)

build.gradle dependencies:

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.locationtech.jts:jts-core:1.19.0'
implementation 'org.hibernate.orm:hibernate-spatial:6.2.6.Final'
implementation 'net.postgis:postgis-jdbc:2.5.1'
implementation 'org.postgresql:postgresql:42.2.27'

This is how my hibernate libs look like. Is it ok to have "duplicates with a different version"?

enter image description here

I've trying adding column definitions, changed around dependencies, and every other option I've found on the internet with no success.

How do I make hibernate recognize the Point type?

I've tried:

  • Adding annotations like you can see in the comments above the entity, but it theoretically does not need it.
  • Using different versions of the dependencies and they don't work either..
  • Changing the dialect also does not work.....
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
lemario
  • 388
  • 1
  • 3
  • 17
  • Does this answer your question? [PostGIS Geometry saving: "Invalid endian flag value encountered."](https://stackoverflow.com/questions/12215212/postgis-geometry-saving-invalid-endian-flag-value-encountered) – K.Nicholas Jul 27 '23 at 13:41
  • No it does not.. I tried adding anotations like you can see in the comments above the entity, but it theoretically does not need it. I've tried using diferent versions of the dependencies and they don't work either.. changing the dialect also does not work...... – lemario Jul 27 '23 at 13:47

1 Answers1

0

So after some digging I got to this question which got me in the right direction.

It was basically springboot - hibernate problem. They look like this now:

id 'org.springframework.boot' version '3.0.1'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.hibernate:hibernate-core:6.1.7.Final'
    implementation 'org.hibernate:hibernate-spatial:6.1.7.Final'
    
    implementation 'net.postgis:postgis-jdbc:2.5.0'
    runtimeOnly 'org.postgresql:postgresql:42.6.0'

Also in spring boot version 3.0.1 you don't need to specify the dialect. So you can delete this:

jpa.properties.hibernate.dialect: org.hibernate.dialect.PostgreSQL95Dialect

The hibernate libs now look fine:

enter image description here

lemario
  • 388
  • 1
  • 3
  • 17