|
With the official JDBC 4.1 driver:
-
Declare the appropriate enum types server-side with CREATE TYPE. The values must match the names of the Java enum values. I recommend using the enum class name (simple or underscored) as the PostgreSQL type name.
-
Declare the tables with the appropriate column types. ALTER TABLE foo ALTER COLUMN TYPE MyEnum USING foo::MyEnum will update an existing string-valued column.
-
Use @Enumerated(STRING) on the selected enum properties on JPA entities.
-
The magic bit: add the query parameter stringtype=unspecified to the JDBC URL to tell the server to allow relaxed binding of incoming string values to database types.
|