0

I'm trying to persist a postgres POINT(x,y) using a custom data persister but ORMLite insists on wrapping my value with quotation marks, which Postgres rejects.

Error i'm getting from the DB:

ERROR: invalid input syntax for type point: "POINT(-115.17913055419922,36.08929443359375)"

Here is how it should look in SQL:

INSERT INTO somegeometries values (POINT(-119.234,36.089))

Here is the important part of the persister:

public PGpointDataPersister() {
    super(SqlType.OTHER, new Class[] {PGpoint.class});
}

public Object javaToSqlArg(FieldType fieldType, Object javaObject) throws SQLException {
    if (javaObject == null) {
        return null;
    }
    PGpoint pt = (PGpoint) javaObject;
    return "POINT(" + pt.x + "," + pt.y + ")";
}

According to Postgresql's documentation this should be supported in the JDBC driver. See https://jdbc.postgresql.org/documentation/80/geometric.html.

I'm using ORMLite 4.48 and the official postgresql JDBC4 driver.

How can i make this work?

  • I created a PGpointType that is a custom type in order to convert before to save it on database: https://stackoverflow.com/questions/53548731/how-to-work-with-pgpoint-for-geolocation-using-postgresql/53754866#53754866 – Jonathan JOhx Dec 13 '18 at 05:40

1 Answers1

0

Turns out all i had to do was return the exact same object and let the JDBC driver do the rest

public Object javaToSqlArg(FieldType fieldType, Object javaObject) throws SQLException {
    return javaObject;
}