I'm working with Hibernate 5.1.0
in a Java application. I'm connecting both to a Postgres 9.5
with Postgis
extensions and Oracle
databases.
I need to find all the geometries in my database that intersect with a given geometry to which I apply a buffer, such as :
Query query = session
.createQuery("select b from Block b where intersects(b.geom, buffer(:geometry, " + bufferDistance + ")) = "
+ UtilsHelper.getTrueBooleanValue(em));
query.setParameter("geometry", geom);
List<Block> blocks = query.list();
That works in Oracle, but in Postgres I will get the error :
Caused by: org.postgresql.util.PSQLException: ERROR: function st_buffer(bytea, numeric) is not unique
Hint: Could not choose a best candidate function. You might need to add explicit type casts.
Position: 243
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
This makes sense, as it will not be able to choose between one of the following functions :
geometry ST_Buffer(geometry g1, float radius_of_buffer);
geography ST_Buffer(geography g1, float radius_of_buffer_in_meters);
The UtilsHelper.getTrueBooleanValue(em)
will just get the right boolean value depending on the entity manager, that is, 0/1 for Oracle and true/false for Postgres.
One obvious solution would be to drop one of the functions. Other than that, is there any way I can fix this?