Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id BE95CB5DBEE for ; Thu, 6 Oct 2011 05:26:52 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 70769-01 for ; Thu, 6 Oct 2011 08:26:52 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by mail.postgresql.org (Postfix) with ESMTP id 14A15B5DBE4 for ; Thu, 6 Oct 2011 05:26:51 -0300 (ADT) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.14.3/8.14.3) with ESMTP id p968QpJs005685 for ; Thu, 6 Oct 2011 08:26:51 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.14.3/8.14.3/Submit) id p968Qpkl005684; Thu, 6 Oct 2011 08:26:51 GMT (envelope-from www) Date: Thu, 6 Oct 2011 08:26:51 GMT Message-Id: <201110060826.p968Qpkl005684@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #6241: JDBC: blob doesnot work with bytea From: "Stefan Franke" Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201110/55 X-Sequence-Number: 31325 The following bug has been logged online: Bug reference: 6241 Logged by: Stefan Franke Email address: stefan@franke.ms PostgreSQL version: 9.1 Operating system: any Description: JDBC: blob doesnot work with bytea Details: To persist a blob you can also use bytea. Unfortunately the JDBC driver does not support this. Especially if you can't control the way how the column is accessed, e.g. using JPA @Lob @Column(name = "DATA") // using bytea private byte[] data; it fails with distinct JPA implementations (e.g. Hibernate) since the JPA layer tries to access it as blob. My workaround is to patch the class org.postgresql.jdbc4.Jdbc4ResultSet: public java.sql.Blob getBlob(int i) throws SQLException { checkResultSet(i); if (wasNullFlag) return null; try { return new Jdbc4Blob(connection, getLong(i)); } catch (PSQLException ex) { // bytea use a dummy Blob return new SerialBlob(getBytes(i)); } }