Re: Reading a Blob field using Hibernate

Fred Toussi via Hsqldb-user <[email protected]> Mon, 19 Aug 2019 08:55:56 +0100
Newsgroups gmane.comp.java.hsqldb.user
Message-ID <[email protected]>
Your code is for testing persistence. It works on Oracle, which is persistent, and fails on the HSQLDB mem: database, which is not persistent if the database is shutdown. Try using an HSQLDB file: database to get a closer match and report if there is still an issue.

The stack trace shows the lob store is empty when you try to retrieve the lob. So in between saving the data and reading it back the database was probably closed.

Regards

Fred Toussi

On Sun, Aug 18, 2019, at 18:30, Jeroen van der Vegt wrote:
> 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
> 
> 
> *Attachments:*
>  * hsqldb_example.java

_______________________________________________
Hsqldb-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user