Re: JPA + enum == Exception

Hudson, Derrick <dhudson@redcom.com>

From: "Hudson, Derrick" <dhudson@redcom.com>
To: "'Marc G. Fournier'" <scrappy@hub.org>, "pgsql-jdbc@postgresql.org" <pgsql-jdbc@postgresql.org>
Date: 2012-12-18T14:25:50Z
Lists: pgsql-hackers
The project I am working on uses enums in PostgreSQL and JPA/Eclipselink.  Our entities use enums in the Java code as well.  We ran into type handling issues like you describe, and solved them by writing converters.  Eclipselink needs to be told how to convert between the PGobject instance used by the JDBC driver and the Java enum value (or String, if that's what you are using in the Java code).

http://www.eclipse.org/eclipselink/api/2.4/org/eclipse/persistence/mappings/converters/Converter.html

http://eclipse.org/eclipselink/documentation/2.4/jpa/extensions/a_converter.htm



-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Marc G. Fournier
Sent: Monday, December 17, 2012 6:02 PM
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] JPA + enum == Exception


I'm trying to use enum's in a database, but the java guys are telling me that they are having problems with inserts ... reading from the database isn't a problem, but there appears to be an issue with converting from string -> enum when saving it back again ...

they are using JPA2 / EJB + Eclipselink ... on the jboss side, we are running the latest jdbc driver ...

considering postgresql has always supported enum and extending types, I think they might be missing something, but I can't think of what to suggest ...

Is there a doc online I can maybe point them to about doing this ... ?