Re: [JDBC] JPA + enum == Exception - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [JDBC] JPA + enum == Exception
Date
Msg-id 28690.1360299322@sss.pgh.pa.us
Whole thread Raw
In response to Re: [JDBC] JPA + enum == Exception  (Tom Dunstan <pgsql@tomd.cc>)
Responses Re: [JDBC] JPA + enum == Exception  (Kevin Grittner <kgrittn@ymail.com>)
Re: [JDBC] JPA + enum == Exception  (Craig Ringer <craig@2ndquadrant.com>)
List 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


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Vacuum/visibility is busted
Next
From: Tom Lane
Date:
Subject: Re: proposal: ANSI SQL 2011 syntax for named parameters