I'm using the spring framework with the JDBC template and I'm also using postgres.
I have tables in postgres that use UUIDs as the primary key and the type of that column is postgres' native UUIDs. How do I store these UUIDs in a prepared statement created through the JDBC template?
I've tried converting the UUID to a string like so:
int rowsAffected = this.jdbc.update(sql, new Object[] {
baseMaterial.getId().toString().toLowerCase(),
baseMaterial.getName(),
baseMaterial.getDescription()
});
but that results in this error:
ERROR: column "id" is of type uuid but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
And if I just use the raw UUID like so:
int rowsAffected = this.jdbc.update(sql, new Object[] {
baseMaterial.getId(),
baseMaterial.getName(),
baseMaterial.getDescription()
});
then I end up with this error:
org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of java.util.UUID. Use setObject() with an explicit Types value to specify the type to use.
Any ideas? This is driving me mad.
The PostgreSQL driver version you are using is 6 years old, and a lot has been changed/improved since. I advise to upgrade to version 42.1.4.
I have scanned the release notes, but I haven't found the specific version they added (or improved) support for UUID.