Re: JPA + enum == Exception - Mailing list pgsql-jdbc

From Craig Ringer
Subject Re: JPA + enum == Exception
Date
Msg-id 50CFB6DB.7030508@2ndquadrant.com
Whole thread Raw
In response to JPA + enum == Exception  ("Marc G. Fournier" <scrappy@hub.org>)
List pgsql-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 …
readingfrom the database isn't a problem, but there appears to be an issue with converting from string -> enum when
savingit 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



pgsql-jdbc by date:

Previous
From: Chen Huajun
Date:
Subject: Re: performance problem of Failover Datasource?
Next
From: Craig Ringer
Date:
Subject: Re: performance problem of Failover Datasource?