Enumerated types and Hibernate - Mailing list pgsql-general

From Emerson Farrugia
Subject Enumerated types and Hibernate
Date
Msg-id b0867d070902120058ye737625vb870baec351daca8@mail.gmail.com
Whole thread Raw
List pgsql-general
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

pgsql-general by date:

Previous
From: Serge Fonville
Date:
Subject: Re: Multiple postgres.exe On Processes
Next
From: Grzegorz Jaśkiewicz
Date:
Subject: Re: Multiple postgres.exe On Processes