From: | Craig Ringer <craig(at)2ndquadrant(dot)com> |
---|---|
To: | "Marc G(dot) Fournier" <scrappy(at)hub(dot)org> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: JPA + enum == Exception |
Date: | 2012-12-18 00:20:43 |
Message-ID: | 50CFB6DB.7030508@2ndquadrant.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers 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 … 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
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2012-12-18 00:30:08 | Re: small pg_basebackup display bug |
Previous Message | Hannu Krosing | 2012-12-17 23:48:01 | Re: multiple CREATE FUNCTION AS items for PLs |
From | Date | Subject | |
---|---|---|---|
Next Message | Craig Ringer | 2012-12-18 00:29:32 | Re: performance problem of Failover Datasource? |
Previous Message | Chen Huajun | 2012-12-18 00:05:54 | Re: performance problem of Failover Datasource? |