Hi, I'm using Hibernate and would like to map a Java enum to a table column defined as an enumerated type. Is this possible?
The following is my SQL: create type day as enum ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'); create table date ( ... day day not null ...); And the following is my Java code: public enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } @Enumerated(EnumType.STRING) public Day getDay() { return day; } When I try to persist an object containing a Day, I get the following exception: Feb 12, 2009 9:32:12 AM org.hibernate.util.JDBCExceptionReporter logExceptions WARNING: SQL Error: 0, SQLState: 42804 Feb 12, 2009 9:32:12 AM org.hibernate.util.JDBCExceptionReporter logExceptions SEVERE: ERROR: column "day" is of type day but expression is of type character varying Using the ordinal enum type in the @Enumerated annotation gives me a similar error, telling me that the expression is of type integer. Is my only option to abandon the PostgreSQL enumerated types and save ordinals or strings directly instead? Any help would be appreciated, Regards, Emerson