0

I am trying to use JDBI with PostgreSQL geometric type and get the following error:

org.jdbi.v3.core.statement.UnableToCreateStatementException with message:   
No argument factory registered for type [com.vividsolutions.jts.geom.Geometry]

The Geometry is part of a bean I am binding with .bindBean().

I found a related question but the answers are not so helpful.

What is the best approach for binding such type?

oshai
  • 14,865
  • 26
  • 84
  • 140

1 Answers1

0

You can convert the Jts geometry to geoJson and then bind the geoJson as string in Jdbi.


public class GeometryUtils {
    private static final GeometryJSON geometryJSON = new GeometryJSON(10);
    
    private static String writeToGeoJson(Geometry geometry) throws IOException {
        final var stringWriter = new StringWriter();
        geometryJSON.write(geometry, stringWriter);
        return stringWriter.toString();
    }
}

and then let's say your sql query looks like this

INSERT INTO XYZ(shape) VALUES (st_geomfromgeojson(:shape::jsonb))    

and bind shape as GeometryUtils.writeToGeoJson(geom)

Sharang Chopra
  • 226
  • 1
  • 10