setBlob() copies the blob, even it was already a PostgreSQL blob! - Mailing list pgsql-jdbc

From Dobes
Subject setBlob() copies the blob, even it was already a PostgreSQL blob!
Date
Msg-id e112f747-7bf4-410d-8efb-fbf90e508875@v12g2000prb.googlegroups.com
Whole thread Raw
Responses Re: setBlob() copies the blob, even it was already a PostgreSQL blob!
List 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.

pgsql-jdbc by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: Using java.lang.Character for "char" data type
Next
From: Kris Jurka
Date:
Subject: Re: no timeout in AbstractJdbc23PoolingDataSource#getPooledConnection