Re: [HACKERS] JPA + enum == Exception

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tom Dunstan <pgsql@tomd.cc>
Cc: "Hudson, Derrick" <dhudson@redcom.com>, "Marc G. Fournier" <scrappy@hub.org>, "pgsql-jdbc@postgresql.org" <pgsql-jdbc@postgresql.org>, pgsql-hackers@postgresql.org
Date: 2013-02-08T04:55:22Z
Lists: pgsql-hackers
Tom Dunstan <pgsql@tomd.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