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?


Unfortunately the answer is no. stringtype is not server parameter. It's JDBC's own client parameter. Check the function here;


and here


You will see that JDBC sets parameter type to VARCHAR or UNSPECIFIED type according to the stringtype property.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.