Reading a Blob field using Hibernate

Jeroen van der Vegt <[email protected]> Sun, 18 Aug 2019 18:59:50 +0200
Newsgroups gmane.comp.java.hsqldb.user
Message-ID <CANmBBXEWhyQitgJkxSPnyk0f6DB03sh027=3njykWaKRfODprg@mail.gmail.com>
Hello all,


I keep running into this exception, but I do not understand why as the code
works fine using Oracle as a database.
For this test, I'm using HSQLDB 2.5.0, Jdk 8.144 and Hibernate 5.2.18, with
the default HSQLDialect in an in-memory HSQLDB database.

I've attached some dummy java code which should make the code I'm using
clear:
First, there is a database entity class called 'MyAttachment', which stores
binary data in a (java.sql.)Blob.
For testing, I store a small amount of data ("this is a test".getBytes())
in an inputStream, and store that as an attachment (see the
streamToDb-method). This seems to work fine, as the Hsqldb DatabaseManager
shows a records with (binary data) in it.

When I try to retrieve the data however, it fails as soon as I try to
access the InputStream (see the getAttachmentData-method). When updating
the code to read some bytes instead of accessing a stream, I get the same
exception (though not wrapped):

java.io.IOException: java.lang.IndexOutOfBoundsException: Index out of
bounds: 0 >= 0
at org.hsqldb.lib.java.JavaSystem.toIOException(Unknown Source)
at org.hsqldb.types.BlobInputStream.read(Unknown Source)
at hsqldb.Test.test(Test.java:53)
...
Caused by: java.lang.IndexOutOfBoundsException: Index out of bounds: 0 >= 0
at org.hsqldb.lib.HsqlArrayList.get(Unknown Source)
at org.hsqldb.persist.LobStoreMem.getBlockBytes(Unknown Source)
at org.hsqldb.persist.LobManager.getBytesNormal(Unknown Source)
at org.hsqldb.persist.LobManager.getBytes(Unknown Source)
at org.hsqldb.Session.performLOBOperation(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
at org.hsqldb.types.BlobDataID.getBytes(Unknown Source)
at org.hsqldb.types.BlobInputStream.readIntoBuffer(Unknown Source)
... 33 more


What is going wrong? As it works with Oracle, I suppose the problem is
Hsqldb-specific?


Kind regards,


*Jeroen van der Vegt *Lead Designer

*T* +31 1 82 59 40 00
*A* Burgemeester Jamessingel 1, P.O. Box 2013, 2800 BD Gouda, The
Netherlands* | W* technolution.nl

This email is intended exclusively for the addressee(s), and may not be
passed on to, or made available for use by any person other than the
addressee(s). Technolution B.V. rules out any and every liability resulting
from any electronic transmission.

_______________________________________________
Hsqldb-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user
hsqldb_example.java (application/octet-stream, 1.3 KB) - not displayed