From: Kris Jurka <books@ejurka.com>
To: Tom Dunstan <tom@tomd.cc>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Hudson, Derrick <dhudson@redcom.com>
Cc: Marc G. Fournier <scrappy@hub.org>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: [HACKERS] JPA + enum == Exception
Date: Fri, 8 Feb 2013 11:26:27 -0500 (EST)
Message-ID: <alpine.BSO.2.00.1302081124290.16163@leary.csoft.net> (raw)
In-Reply-To: <CAPPfruybG_s7O9x=qQHo79SiT0J_YumsbBQA01VDJEkNnm2E9Q@mail.gmail.com>
References: <EDDA5C6D-77E3-4C56-B33B-277E7FB32A12@hub.org>
<401084E5E73F4241A44F3C9E6FD794289CE24D03@exch-01>
<CAPPfruyta0A0xGhG4Zh785sS0_FZ8GczzcjZGXo2yfPhaDxuaA@mail.gmail.com>
<28690.1360299322@sss.pgh.pa.us>
<CAPPfruybG_s7O9x=qQHo79SiT0J_YumsbBQA01VDJEkNnm2E9Q@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
On Fri, 8 Feb 2013, Tom Dunstan wrote:
> On 8 February 2013 15:25, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> > AFAIK this is just business as usual with JDBC: setString() implies that
> > the parameter is of a string type. It'll fall over if the type actually
> > required is anything but a string. (I'm no Java expert, but I seem to
> > recall that using setObject instead is the standard workaround.)
> >
>
> Yes, you can use setObject(1, "enumval", Types.OTHER). I was hoping
> that setString might work, as mapping java enum values to strings in
> the database is a very common ORM technique that is built into
> basically all major ORMs including all that support the JPA standard,
> and it leads to people using varchars instead of typesafe enums in
> their dbs.
The other workaround is to use the url parameter stringtype=unspecified to
have setString always bind to unknown instead of varchar, which then
shouldn't require any code changes.
Kris Jurka
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
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: books@ejurka.com, tom@tomd.cc, tgl@sss.pgh.pa.us, dhudson@redcom.com, scrappy@hub.org
Subject: Re: [HACKERS] JPA + enum == Exception
In-Reply-To: <alpine.BSO.2.00.1302081124290.16163@leary.csoft.net>
References: <EDDA5C6D-77E3-4C56-B33B-277E7FB32A12@hub.org> <401084E5E73F4241A44F3C9E6FD794289CE24D03@exch-01> <CAPPfruyta0A0xGhG4Zh785sS0_FZ8GczzcjZGXo2yfPhaDxuaA@mail.gmail.com> <28690.1360299322@sss.pgh.pa.us> <CAPPfruybG_s7O9x=qQHo79SiT0J_YumsbBQA01VDJEkNnm2E9Q@mail.gmail.com> <alpine.BSO.2.00.1302081124290.16163@leary.csoft.net>
* 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