Enumerated types and Hibernate

Поиск
Список
Период
Сортировка
От Emerson Farrugia
Тема Enumerated types and Hibernate
Дата
Msg-id b0867d070902120058ye737625vb870baec351daca8@mail.gmail.com
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: Serge Fonville
Дата:
Сообщение: Re: Multiple postgres.exe On Processes
Следующее
От: Grzegorz Jaśkiewicz
Дата:
Сообщение: Re: Multiple postgres.exe On Processes