I use H2 database extensively when it comes to testing the persistence layer of a spring boot application. It is very easy to configure spring to use it for tests or in development environments.

However, if I need to deal with spatial datatypes like geometry, it is not obvious anymore how to configure H2 db so that it can store and query spatial data. The geometry datatype is supported by H2 out of the box which means storing geometries is not an issue. However, a geometry column cannot be used in filter expression (where part of an SQL query), H2 doesn't know on it's own how to work with spatial data. Since I want to test all my repository methods -including the ones that utilize spatial filters- I need to make H2 capable of handling spatial data.

To achive the goal the we need an extra dependency which is H2GIS. The latest release of H2GIS is 1.5.0 which depends on H2 v1.4.197. This very important, H2GIS v1.5.0 won't work with the latest H2 release.

We alson need to set "spring.jpa.database-platform" property to "org.hibernate.spatial.dialect.h2geodb.GeoDBDialect".

Example spring boot project can be found here.

Credit: https://stackoverflow.com/questions/60541794/spring-boot-app-with-embedded-h2gis-initialization-throws-sql-syntax-error