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
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-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

Browse pgsql-hackers by date

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

Browse pgsql-jdbc by date

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