Issue Details (XML | Word | Printable)

Key: HB-955
Type: Bug Bug
Status: Closed Closed
Resolution: Rejected
Priority: Minor Minor
Assignee: Gavin King
Reporter: Steve Lustbader
Votes: 2
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
z - Hibernate 2

Postres and Blobs

Created: 13/May/04 09:56 AM   Updated: 12/Feb/05 11:12 PM   Resolved: 21/May/04 01:54 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

Bug Testcase Reminder (view):
REMINDER: Bug reports should generally be accompanied by a test case
Participants: Christian Bauer, Dimitry Mardiyan, Gavin King, Mike Heath, Steve Lustbader and Tim McCune


 Description  « Hide

It appears that Hibernate's support for blobs (or large objects) is broken with Postgres 7.2 and later. Those versions of Postgres support using OID columns for large objects. The PostgreSQLDialect should be changed to register a column type of "OID" for the BLOB type.

Also, the BlobType class should also be changed. In the set(...) method, PreparedStatement.setBlob() works with OID columns, so only the else branch is needed.



Dimitry Mardiyan added a comment - 15/May/04 06:57 AM

Why the priority is minor for this request?
Is there a workaround?


Steve Lustbader added a comment - 17/May/04 02:40 PM

If you extend the two classes with the changes mentioned, hibernate will successfully work with postgres and blobs.


Christian Bauer added a comment - 21/May/04 01:33 PM

Gavin, in BlobType, I couldn't figure out why you are using setBinaryStream() when the value is a BlobImpl. It looks to me like it shouldn't make a difference who created the Blob, and BlobImpl is just what you get if you use the Hibernate.createBlob() shortcuts. However, I can confirm that PostgreSQL >= 7.2 supports Blobs with the two changes mentioned in this issue. I just couldn't figure out if the changed BlobType breaks anything.


Gavin King added a comment - 21/May/04 01:54 PM

It breaks on dbs that try to cast the blob to their own impl.


Steve Lustbader added a comment - 18/Jun/04 01:27 PM

It's already broken. Adding this patch might not make it completely right, but it would be less broken then before.


Gavin King added a comment - 19/Jun/04 12:34 PM

Well, the first change (use OID as the column type) might work ok. The second change is definitely unnecessary, and is the correct thing to do on non-broken JDBC drivers.


Tim McCune added a comment - 20/Oct/04 12:41 AM

Why was this bug closed? There was no explanation of why PostgreSQLDialect maps Types.BLOB to BYTEA instead of OID. I ran into the same problem as the submitter, and changing the mapping from BYTEA to OID in the dialect made everything start working. The BYTEA mapping is completely broken, and will throw a SQLException every time you try to use a Blob. It's a 1 line change. Please reopen this bug and fix it.


Gavin King added a comment - 20/Oct/04 03:12 AM

I tested the change to OID, and type="blob" is still broken on existing postgres JDBC drivers. When postgres features working blob support, we can revisit.


Mike Heath added a comment - 11/Feb/05 06:24 PM

I don't understand why this issue was rejected.

I am of the opinion that Hibernate is broken and have to agree with Steve Lustbader. Gavin wrote: "When postgres features working blob support, we can revisit."

Blob support works fine in Postgres. We are able to use Blobs without any problems using plain JDBC. So, let's revisit this issue.

When using setBinaryStream, the Postgres JDBC driver epects a bytea (Byte Array) field. If you're going to use Blobs in Postgres you can NOT use getBinaryStream() and setBinaryStream(). I do not consider this to be a problem with the Postgres JDBC driver. There was a thread discussing the whole not mixing Blobs with Binary streams at http://archives.postgresql.org/pgsql-jdbc/2005-01/msg00029.php

Our workaround right now is that we copied the implementation of net.sf.hibernate.lob.BlobImpl to a different class. We use this implementation of Blob to get around the problem of using Blobs with Hibernate and Postgres. A better solution would be to fix Hibernate so that when using Blobs, it uses Blobs and not BinaryStreams.


Gavin King added a comment - 11/Feb/05 07:56 PM

The problem is: where the hell do I get an instance of Blob from when I am inserting new data?


Gavin King added a comment - 11/Feb/05 09:10 PM

OK, so I've now managed to make both blob and clob type work on Postgres, in the HB3 branch. We can backport this change quite easily.


Mike Heath added a comment - 12/Feb/05 11:12 PM

Excellent. Your fix looks great and is very ingeneous. Thanks for making this change.