Thread: Two BLOBs (OID) in table?

Two BLOBs (OID) in table?

From
Stanislav Mironov
Date:
Hello All!

I created entity with 2 BLOB columns in one table: one for image and one
for thumbnail. Storing image and getting it back in another session
works pretty good.

But when I set thumbnail BLOB successfully, the original BLOB becomes
empty. Retrieved entity returns length 0 for image BLOB.

@Lob private Blob image;
@Lob private Blob thumbnail;

Hibernate 3.2.6, Annotations 3.3.0, PostgreSQL 8.3.1, JDBC 8.3-603.
The problem is 100% reproducible. Please, help?

--
Stanislav Mironov

Re: Two BLOBs (OID) in table?

From
Kris Jurka
Date:

On Sun, 13 Apr 2008, Stanislav Mironov wrote:

> I created entity with 2 BLOB columns in one table: one for image and one for
> thumbnail. Storing image and getting it back in another session works pretty
> good.
>
> But when I set thumbnail BLOB successfully, the original BLOB becomes empty.
> Retrieved entity returns length 0 for image BLOB.
>
> @Lob private Blob image;
> @Lob private Blob thumbnail;
>
> Hibernate 3.2.6, Annotations 3.3.0, PostgreSQL 8.3.1, JDBC 8.3-603.
> The problem is 100% reproducible. Please, help?
>

It's not clear what JDBC calls this actually involves, so it's difficult
to tell where things are going wrong.  If you can create a test case that
shows the failure using the postgresql JDBC driver alone, I'd be happy to
look at it.

Kris Jurka

Re: Two BLOBs (OID) in table?

From
Stanislav Mironov
Date:
Kris Jurka wrote:
> On Sun, 13 Apr 2008, Stanislav Mironov wrote:
>> I created entity with 2 BLOB columns in one table: one for image and
>> one for thumbnail. Storing image and getting it back in another
>> session works pretty good.
>>
>> But when I set thumbnail BLOB successfully, the original BLOB becomes
>> empty. Retrieved entity returns length 0 for image BLOB.
>>
>> @Lob private Blob image;
>> @Lob private Blob thumbnail;
>>
>> Hibernate 3.2.6, Annotations 3.3.0, PostgreSQL 8.3.1, JDBC 8.3-603.
>> The problem is 100% reproducible. Please, help?
>>
>
> It's not clear what JDBC calls this actually involves, so it's
> difficult to tell where things are going wrong.  If you can create a
> test case that shows the failure using the postgresql JDBC driver
> alone, I'd be happy to look at it.

Sorry, I cannot emulate Hibernate (it's too complicated), but I've
created hibernate test that reproduces this bug.
After some experiments it seems like I've figured out bug sequence: it
happens because I create thumbnail BLOB with data from image BLOB.

1. getBinaryStream or getBytes on first BLOB before setting second BLOB
causes first BLOB truncation to zero.

2. Any access (even length()) to first BLOB after setting second BLOB
with setBlob and executeUpdate causes this bug:
SEVERE: ERROR: invalid large-object descriptor: 0
org.postgresql.util.PSQLException: ERROR: invalid large-object descriptor: 0
    at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1548)
    at
org.postgresql.core.v3.QueryExecutorImpl.receiveFastpathResult(QueryExecutorImpl.java:586)
    at
org.postgresql.core.v3.QueryExecutorImpl.fastpathCall(QueryExecutorImpl.java:485)
    at org.postgresql.fastpath.Fastpath.fastpath(Fastpath.java:74)
    at org.postgresql.fastpath.Fastpath.fastpath(Fastpath.java:114)
    at org.postgresql.fastpath.Fastpath.getInteger(Fastpath.java:126)
    at org.postgresql.largeobject.LargeObject.tell(LargeObject.java:264)
    at org.postgresql.largeobject.LargeObject.size(LargeObject.java:279)
    at
org.postgresql.jdbc2.AbstractJdbc2BlobClob.length(AbstractJdbc2BlobClob.java:44)
    at org.hibernate.lob.SerializableBlob.length(SerializableBlob.java:31)
    at
ru.smilabs.mir.centre.db.PostgreSQLTest$3.run(PostgreSQLTest.java:142)

When I replace first BLOB access with fake generated data - everything
works perfectly as it should. Both BLOBs are stored and retrieved right.
Also original code worked fine with Apache Derby, H2 and MySQL so this
makes me think the trouble is on PostgreSQL JDBC side.

I'm ready to provide more data on demand.
Thanks in advance!

--
Stanislav Mironov

Re: Two BLOBs (OID) in table?

From
Kris Jurka
Date:

On Mon, 14 Apr 2008, Stanislav Mironov wrote:

> Sorry, I cannot emulate Hibernate (it's too complicated), but I've created
> hibernate test that reproduces this bug.

Could you send us that test code?

Kris Jurka

Re: Two BLOBs (OID) in table?

From
Kris Jurka
Date:

On Mon, 14 Apr 2008, Kris Jurka wrote:

> On Mon, 14 Apr 2008, Stanislav Mironov wrote:
>
>> Sorry, I cannot emulate Hibernate (it's too complicated), but I've created
>> hibernate test that reproduces this bug.
>
> Could you send us that test code?
>

Do you still have this test?  Can you send it?

Kris Jurka