1

I have this function where I get a hibernate spatial Geometry type and buffer it in meters like so


entityManager
.createNativeQuery(“SELECT ST_BUFFER(GEOGRAPHY(:geometry), :margin, ‘join=mitre’) AS BUFFERED_GEOMETRY”)
.setParameter(“geometry”, geometry)
.setParameter(“margin”, margin)
.unwrap(NativeQuery.class)
.addScalar(“ BUFFERED_GEOMETRY”, new JTSGeometryType(PGGeometryTypeDescriptor.INSTANCE))
.getSingleResult();

This code works perfectly when I use postGIS but when I use h2GIS in my tests I get a sql error

Function “GEOGRAPHY” not found

I indeed saw that this function and some others don’t exist in the H2GISFunctions.class. Is there a way around this? Except using Postgres in my tests?

1 Answers1

0

I don't know H2GIS, but PostgreSQL is almost as fast as H2 if you avoid most DDL and use TRUNCATE for clearing data between tests, so why wouldn't you want to test against the database that you also use in production?

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58
  • This tests is part of bigger test module that is already using h2 and i really don’t want to refactor or effect all the other tests – יהונתן בן דוד Dec 22 '20 at 09:57
  • I don't have an answer for you then. You could try to implement these H2 functions yourself though. Not sure how hard it is to implement a `GEOGRAPHY` function, but since you can use Java to implement functions in H2, it shouldn't be too hard. – Christian Beikov Dec 22 '20 at 14:41