Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U3fzi-0001TB-Hu for pgsql-jdbc@arkaria.postgresql.org; Fri, 08 Feb 2013 04:55:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U3fzh-00025p-Em for pgsql-jdbc@arkaria.postgresql.org; Fri, 08 Feb 2013 04:55:25 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U3fzg-00025L-IF for pgsql-jdbc@postgresql.org; Fri, 08 Feb 2013 04:55:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U3fze-0001Ye-Vb for pgsql-jdbc@postgresql.org; Fri, 08 Feb 2013 04:55:23 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r184tM8v028691; Thu, 7 Feb 2013 23:55:22 -0500 (EST) From: Tom Lane To: Tom Dunstan cc: "Hudson, Derrick" , "Marc G. Fournier" , "pgsql-jdbc@postgresql.org" , pgsql-hackers@postgresql.org Subject: Re: [HACKERS] JPA + enum == Exception In-reply-to: References: <401084E5E73F4241A44F3C9E6FD794289CE24D03@exch-01> Comments: In-reply-to Tom Dunstan message dated "Fri, 08 Feb 2013 15:09:35 +1030" Date: Thu, 07 Feb 2013 23:55:22 -0500 Message-ID: <28690.1360299322@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Tom Dunstan 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 -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc