|
If you extend the two classes with the changes mentioned, hibernate will successfully work with postgres and blobs. 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. It breaks on dbs that try to cast the blob to their own impl. It's already broken. Adding this patch might not make it completely right, but it would be less broken then before. 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. 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. 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. 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. The problem is: where the hell do I get an instance of Blob from when I am inserting new data? 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. Excellent. Your fix looks great and is very ingeneous. Thanks for making this change. |
||||||||||||||||||||||||||||||||||||||||||||
Why the priority is minor for this request?
Is there a workaround?