Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring data jdbc: how to use Point from org.springframework.data.geo package

I have an entity

public class Arena {
    @Id
    private final Long id;
    @Embedded(onEmpty = Embedded.OnEmpty.USE_NULL)
    final Point location;
}

Point comes from org.springframework.data.geo package

and Postgres schema to it

CREATE TABLE arena
(
    id                 SERIAL                       NOT NULL
        CONSTRAINT arena_pk
            PRIMARY KEY,
    location           POINT
);

when I'm trying to use the entity via spring data jdbc repository (arenaRepository.findAll())

public interface ArenaRepository extends CrudRepository<Arena, Long> {
}

I get an error

Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT arena.id AS id, arena.y AS y, arena.x AS x FROM arena]; nested exception is org.postgresql.util.PSQLException: ERROR: column arena.y does not exist

I see that SQL does not match schema. But is it possible to work with 'geo' classes via Spring Data Jdbc?

I tried introduce location as List and it works. Is it the right way?

like image 200
Pavel Varchenko Avatar asked May 20 '26 09:05

Pavel Varchenko


1 Answers

You may annotate the field containing the org.springframework.data.geo.Point with @Embedded. This will map it to two columns x and y.

I currently don't see a way to map it to a Postgres Point column. There certainly isn't any special support for that.

like image 123
Jens Schauder Avatar answered May 22 '26 07:05

Jens Schauder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!