I am trying to persist GIS point data in spring-boot 2.6 with a H2 in mem database.
I have followed the setup as per here with the exception of the newer spring-boot version.
My build.gradle
plugins {
id 'org.springframework.boot' version '2.6.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.nz'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
ext {
set('azureVersion', "3.14.0")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.azure.spring:azure-spring-boot-starter-active-directory'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation group: 'com.h2database', name: 'h2', version: '1.4.197'
//implementation group: 'org.locationtech.jts', name: 'jts-core', version: '1.18.2'
implementation group: 'com.graphhopper.external', name: 'jackson-datatype-jts', version: '1.0-2.7'
implementation group: 'org.hibernate', name: 'hibernate-spatial', version: '6.0.0.CR2', ext: 'pom'
implementation group: 'org.orbisgis', name: 'h2gis', version: '1.5.0'
}
my application.properties
spring.jpa.hibernate.ddl-auto=update
spring.jpa.defer-datasource-initialization=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
# Initialise H2 with H2GIS for spatial support – see schema-h2.sql also
spring.datasource.platform=h2
spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.h2geodb.GeoDBDialect
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
My schema.sql
-- Needed to add H2GIS support for spatial data types
CREATE ALIAS IF NOT EXISTS H2GIS_SPATIAL FOR "org.h2gis.functions.factory.H2GISFunctions.load";
CALL H2GIS_SPATIAL();
Abbreviated entity
@Id
@GeneratedValue(strategy = AUTO)
private Long id;
@Column(columnDefinition = "POINT")
@JsonSerialize(using = GeometrySerializer.class)
@JsonDeserialize(using = GeometryDeserializer.class)
private Point location;
But I get the following error when I try to run:
org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.spatial.dialect.h2geodb.GeoDBDialect] as strategy [org.hibernate.dialect.Dialect]
Could not obtain connection to query metadata org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [ org.hibernate.spatial.dialect.h2geodb.GeoDBDialect] as strategy [org.hibernate.dialect.Dialect]
– Randellrandene