Initialise H2GIS with Spring Boot JPA

Posted on August 11, 2023
Tags: jpa, java, spring

TL;DR

spring:
  jpa:
    generate-ddl: true
    properties:
      javax:
        persistence:
          schema-generation:
            database:
              action: drop-and-create
            create-source: script-then-metadata
            create-script-source: init.sql

init.sql

CREATE ALIAS IF NOT EXISTS H2GIS_SPATIAL FOR "org.h2gis.functions.factory.H2GISFunctions.load";
CALL H2GIS_SPATIAL();

CREATE DOMAIN POINT AS GEOMETRY(POINT);
CREATE DOMAIN POLYGON AS GEOMETRY(POLYGON);