Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] JPA + enum == Exception

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tom Dunstan <pgsql(at)tomd(dot)cc>
Cc: "Hudson, Derrick" <dhudson(at)redcom(dot)com>, "Marc G(dot) Fournier" <scrappy(at)hub(dot)org>, "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] JPA + enum == Exception
Date: 2013-02-08 04:55:22
Message-ID: 28690.1360299322@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-jdbc
Tom Dunstan <pgsql(at)tomd(dot)cc> writes:
> ... That works ok, but when attempting to use a prepared statement:

>     ps = con.prepareStatement("insert into enumcast values (?)");
>     ps.setString(1, "meh");
>     ps.executeUpdate();

> we get a

> org.postgresql.util.PSQLException: ERROR: column "current_mood" is of
> type mood but expression is of type character varying
>   Hint: You will need to rewrite or cast the expression.

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.)

Enums are not suffering any special hardship here, and I'd be against
weakening the type system to give them a special pass.

			regards, tom lane


In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2013-02-08 05:05:12
Subject: Re: proposal: ANSI SQL 2011 syntax for named parameters
Previous:From: Tom LaneDate: 2013-02-08 04:47:29
Subject: Re: Vacuum/visibility is busted

pgsql-jdbc by date

Next:From: Tom DunstanDate: 2013-02-08 05:45:32
Subject: Re: [HACKERS] JPA + enum == Exception
Previous:From: Tom DunstanDate: 2013-02-08 04:46:57
Subject: Re: Publish artifacts to Maven central

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group