setBlob() copies the blob, even it was already a PostgreSQL blob!

From: Dobes <dobesv(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: setBlob() copies the blob, even it was already a PostgreSQL blob!
Date: 2010-05-27 21:37:25
Message-ID: e112f747-7bf4-410d-8efb-fbf90e508875@v12g2000prb.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi there,

Looking at org.postgresql.jdbc2.AbstractJdbc2Statement.setBlob(int,
Blob) it seems to copy the given blob, even if the blob was already a
PostgreSQL blob.

Ideally it would use the blob if it was already a PostgreSQL blob.

Why? If you're using Blob object with Hibernate it can be useful to
create the blob in a new entity and write some stuff to it before
saving to the DB along with the entity. Also, I suspect (but have not
yet confirmed) that hibernate will store the blob fields any time an
object is updated to the database along with the other fields (i.e. it
doesn't necessarily UPDATE only the changed fields, it may issue an
UPDATE that includes the blob's OID and uses the setBlob() method to
set it).

The way things are now took me quite by surprise and we can have a lot
of duplicate copies of the data in the database, poor performance,
etc.. It seems like an easy fix to check whether the blob passed in
is already a PostgreSQL blob and if so, re-use the same oid already
allocated.

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2010-05-28 18:37:26 Re: no timeout in AbstractJdbc23PoolingDataSource#getPooledConnection
Previous Message Kevin Grittner 2010-05-27 19:41:14 Re: Using java.lang.Character for "char" data type