In a Spring Boot application (h2 in-memory database + Hibernate Spatial) in a Junit test, I'm getting error "Function "ST_WITHIN" not found" for a "within" query
pom.xml:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
</dependency>
test/resources/application.properties:
spring.datasource.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=va
spring.jpa.database=h2
spring.jpa.database-platform=org.hibernate.spatial.dialect.h2geodb.GeoDBDialect
LocationRepository.java
@Query(value = "select l from Location l where within(l.position, :box) = true")
List<Location> findByPositionWithin(@Param("box") org.locationtech.jts.geom.Geometry box);
LocationEntity.java
@Column(columnDefinition = "GEOMETRY")
private org.locationtech.jts.geom.Point position;
Obviously, the alias ST_WITHIN is missing. Any ideas how to fix this?
GEOMETRYdata type. You can try to use H2GIS with Hibernate Spatial instead with the sameGeoDBDialect. Compatible versions of H2 and H2GIS need to be used, and H2GIS needs to be initialized withCREATE ALIAS IF NOT EXISTS H2GIS_SPATIAL FOR "org.h2gis.functions.factory.H2GISFunctions.load"; CALL H2GIS_SPATIAL();.