Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-jdbc by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group