开发者

Postgresql 8.4 reading OID style BLOBs with Hibernate

I am getting this weird case when querying Postgres 8.4 for some records with Blobs (of type OIDs) with Hibernate. The query does return all right but when my code wants to read the content of the BLOB with the simple code below, it gets 0 bytes back

public static byte[] readBlob(Blob blob) throws Exception {
    InputStream is = null;
    try {
        is = blob.getBinaryStream();
        return org.apache.commons.io.IOUtils.toByteArray(is);
    }
    finally {
        if开发者_JAVA百科 (is != null)
            try {
                is.close();
            }
            catch(Exception e) {}
    }
}

Funny think is that I am getting this behavior only since I've started adding more then one such records to the table. The underlying JDBC library is type 3 (postgresq 8.4-701). Can someone give me a hint as to how to solve this issue? Thanks

Peter


Looks like you may have found this bug: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4876


It was a while since I have run into similar issue, and since I've refreshed my memories about this topic I am thinking of sharing the results. The problem is that Postgres (and a few versions back Oracle too) will not handle the Blob content at the record creation time in the same transaction. Funny think is that one needs to pass the content after the external file (where the content gets stored eventually) has been well created and reserved for the operation. Yes, the record gets created but the Blob is blank. To have the Blob filled out with whatever you need to put in, you need that operation in a second transaction (sort of an update record). That's a funny business (maybe a major bug), ehe

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜