I am trying to get Hibernate to save Java enum fields as enum columns in PostgreSQL 9.6. If I map the fields as
@Enumerated(STRING), Hibernate naively uses the enum name as the column contents. This works splendidly for reads (it just gets the string representation, matches up and returns), but the server complains about the type mismatch when writing:
expression is of type character varying.
The PostgreSQL JDBC driver has a parameter
stringtype that will tell the server to infer the appropriate column type for string values, and using
stringtype=unspecified successfully gets enum values stored. However, I will be deploying my application in an environment where the JDBC connection string is supplied externally, and it's not practical to add the
stringtype property to it.
Is there a way I can configure the server (such as with a
SET command) to treat connections as
stringtype=unspecified by default?