pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@2ndquadrant.com>
To: Marc G. Fournier <scrappy@hub.org>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: JPA + enum == Exception
Date: Tue, 18 Dec 2012 08:20:43 +0800
Message-ID: <50CFB6DB.7030508@2ndquadrant.com> (raw)
In-Reply-To: <EDDA5C6D-77E3-4C56-B33B-277E7FB32A12@hub.org>
References: <EDDA5C6D-77E3-4C56-B33B-277E7FB32A12@hub.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

On 18/12/2012 7:01 AM, Marc G. Fournier wrote:
> 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 …
You will have issues, and this is a real PITA. You need a custom type
handler in EclipseLink to use the JDBC `setObject(...)` method to set
the enum. If you use `setString(...)` as is the default when you use a
string mapping, PgJDBC will send a parameter of type `text`, and
PostgreSQL will complain that it cannot implicitly cast `text` to
whatever your enum is.

Creating an implicit cast from text to your enum type in the database
will work around it.

The root of the problem is that PostgreSQL is much too fussy about
casting from `text` to other types.

Please follow up with details if you want help:

- Exact PgJDBC version, not just "the latest"
- EclipseLink version
- PostgreSQL version
- EXACT TEXT OF THE ERROR MESSAGE YOU GET
- The query/queries that resulted in the error mesage, as shown in the
PostgreSQL logs. You might need to set `log_statement = 'all'` to
capture them.

-- 
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (21+ messages)  latest in thread

Message-ID: <50CFB6DB.7030508@2ndquadrant.com>
Permalink:  ../50CFB6DB.7030508@2ndquadrant.com/
Also on:    postgresql.org/message-id/50CFB6DB.7030508@2ndquadrant.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: craig@2ndquadrant.com, scrappy@hub.org
  Subject: Re: JPA + enum == Exception
  In-Reply-To: <50CFB6DB.7030508@2ndquadrant.com>
  References: <EDDA5C6D-77E3-4C56-B33B-277E7FB32A12@hub.org> <50CFB6DB.7030508@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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