pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Java persistence with enum types
4+ messages / 4 participants
[nested] [flat]

* Java persistence with enum types
@ 2009-05-23 14:02  Susannah Relf <cyclingrelf@googlemail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Susannah Relf @ 2009-05-23 14:02 UTC (permalink / raw)
  To: pgsql-jdbc

Hi, I have an enum type in my postgres 8.3 database:

CREATE TYPE typeOfNames AS ENUM ('Latin', 'Common', 'Local');

I am trying to access the database through the Java Persistence API using
Netbeans:
    @Lob
    @Column(name = "typeofname")
    private String typeofname;

This works for reading from the database, but writing to it, I get the error
message:
Caused by: org.postgresql.util.PSQLException: ERROR: column "typeofname" is
of type typeofnames but expression is of type character varying

Anyone got any suggestions?

Thanks

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Java persistence with enum types
@ 2009-05-24 06:29  Craig Ringer <craig@postnewspapers.com.au>
  parent: Susannah Relf <cyclingrelf@googlemail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Craig Ringer @ 2009-05-24 06:29 UTC (permalink / raw)
  To: Susannah Relf <cyclingrelf@googlemail.com>; +Cc: pgsql-jdbc

Susannah Relf wrote:
> Hi, I have an enum type in my postgres 8.3 database:
> 
> CREATE TYPE typeOfNames AS ENUM ('Latin', 'Common', 'Local');
> 
> I am trying to access the database through the Java Persistence API using
> Netbeans:
>     @Lob
>     @Column(name = "typeofname")
>     private String typeofname;

One minute with Google:

@Enumerated
http://java.sun.com/javaee/5/docs/api/javax/persistence/Enumerated.html

http://forums.java.net/jive/thread.jspa?messageID=240608
http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#Enu...
... etc ...

--
Craig Ringer



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Java persistence with enum types
@ 2009-05-25 12:01  Susannah <cyclingrelf@googlemail.com>
  parent: Craig Ringer <craig@postnewspapers.com.au>
  0 siblings, 1 reply; 4+ messages in thread

From: Susannah @ 2009-05-25 12:01 UTC (permalink / raw)
  To: pgsql-jdbc


Hi,

Thanks for trying to help Craig, but I had tried the @enumerated annotation
already with the same error message. The @enumerated annotation doesn't
return an enum type to Postgres, but instead returns the ordinal value (by
default) or a string value of the enum. This means I get either the error
message:

Caused by: org.postgresql.util.PSQLException: ERROR: column "typeofname" is
of type typeofnames but expression is of type character varying
(if I use enumtype STRING)

Or

Caused by: org.postgresql.util.PSQLException: ERROR: column "typeofname" is
of type typeofnames but expression is of integer



Craig Ringer wrote:
> 
> Susannah Relf wrote:
>> Hi, I have an enum type in my postgres 8.3 database:
>> 
>> CREATE TYPE typeOfNames AS ENUM ('Latin', 'Common', 'Local');
>> 
>> I am trying to access the database through the Java Persistence API using
>> Netbeans:
>>     @Lob
>>     @Column(name = "typeofname")
>>     private String typeofname;
> 
> One minute with Google:
> 
> @Enumerated
> http://java.sun.com/javaee/5/docs/api/javax/persistence/Enumerated.html
> 
> http://forums.java.net/jive/thread.jspa?messageID=240608
> http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#Enu...
> ... etc ...
> 
> --
> Craig Ringer
> 
> -- 
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
> 
> 

-- 
View this message in context: http://www.nabble.com/Java-persistence-with-enum-types-tp23684815p23705886.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Java persistence with enum types
@ 2009-05-26 15:17  The Jasper <thejasper@gmail.com>
  parent: Susannah <cyclingrelf@googlemail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: The Jasper @ 2009-05-26 15:17 UTC (permalink / raw)
  To: pgsql-jdbc

On Mon, May 25, 2009 at 2:01 PM, Susannah <cyclingrelf@googlemail.com> wrote:
>
> Hi,
>
> Thanks for trying to help Craig, but I had tried the @enumerated annotation
> already with the same error message. The @enumerated annotation doesn't
> return an enum type to Postgres, but instead returns the ordinal value (by
> default) or a string value of the enum. This means I get either the error
> message:
>
> Caused by: org.postgresql.util.PSQLException: ERROR: column "typeofname" is
> of type typeofnames but expression is of type character varying
> (if I use enumtype STRING)
>
> Or
>
> Caused by: org.postgresql.util.PSQLException: ERROR: column "typeofname" is
> of type typeofnames but expression is of integer

I think you have the same problem I did a while back. A colleague of
mine figured it out. There is a partial answer here:
http://stackoverflow.com/questions/851758/java-enums-jpa-and-postgres-enums-how-do-i-make-them-work-...

Don't have time to dig up and clean up the actual code we use now but
I can if you'd like (and you're not in a hurry).

mvg,

Jasper
-- 
http://xkcd.com/583/



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2009-05-26 15:17 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-05-23 14:02 Java persistence with enum types Susannah Relf <cyclingrelf@googlemail.com>
2009-05-24 06:29 ` Craig Ringer <craig@postnewspapers.com.au>
2009-05-25 12:01   ` Susannah <cyclingrelf@googlemail.com>
2009-05-26 15:17     ` The Jasper <thejasper@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox