-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: PostgreSQL enumerated types
PostPosted: Thu Feb 12, 2009 1:00 pm 
Newbie

Joined: Wed Sep 12, 2007 1:58 pm
Posts: 12
Hi,

I would like to map a Java enum to a table column defined as a PostgreSQL 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



Hibernate version: 3.3.1
Name and version of the database you are using: PostgreSQL 8.3.5


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.