Blob.setBinaryStream(1) throws Invalid value "1" for parameter "length" [90008-190]

221 views
Skip to first unread message

Alexandra Cohen

unread,
Dec 28, 2015, 3:43:05 PM12/28/15
to H2 Database
I'm trying to create blob via Hibernate 4.3.5 API. H2 1.4.190 in-memory. Originally code was written for Oracle DB and now we are trying to use H2 for unit testing.

Blob blob = Hibernate.getLobCreator(hibernateSession).createBlob(new byte[]{0});
blob.setBinaryStream(1);

During createBlob() stack is following:

at org.h2.value.ValueLobDb.<init>(ValueLobDb.java:75)
at org.h2.value.ValueLobDb.createSmallLob(ValueLobDb.java:667)
at org.h2.value.ValueLobDb.createSmallLob(ValueLobDb.java:654)
at org.h2.store.LobStorageMap.createBlob(LobStorageMap.java:162)
at org.h2.jdbc.JdbcConnection.createBlob(JdbcConnection.java:1826)
at org.h2.jdbc.JdbcBlob.setBytes(JdbcBlob.java:124)
at org.hibernate.engine.jdbc.ContextualLobCreator.createBlob(ContextualLobCreator.java:68)

And precision is set to 1 in constructor (because of single byte array used as createBlob argument?). Next setBinaryStream(1) throws exception.

Am I doing something incorrectly or is this H2 issue? 

Noel Grandin

unread,
Dec 29, 2015, 1:59:21 PM12/29/15
to h2-da...@googlegroups.com
what exactly is the exception and stack trace that gets thrown?
> --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to h2-database...@googlegroups.com.
> To post to this group, send email to h2-da...@googlegroups.com.
> Visit this group at https://groups.google.com/group/h2-database.
> For more options, visit https://groups.google.com/d/optout.

Alexandra Cohen

unread,
Jan 5, 2016, 7:24:12 AM1/5/16
to H2 Database
Exception is the following:

org.h2.jdbc.JdbcSQLException: Invalid value "1" for parameter "length" [90008-190]

at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.getInvalidValueException(DbException.java:228)
at org.h2.jdbc.JdbcBlob.setBinaryStream(JdbcBlob.java:183)

Noel Grandin

unread,
Jan 5, 2016, 12:57:12 PM1/5/16
to h2-da...@googlegroups.com
Something like this might work:

Blob blob = Hibernate.getLobCreator(hibernateSession).createBlob(new byte[0]);

blob.setBinaryStream(1);
For some reason Hibernate does not seem to have an API to create a
proper empty Blob and it is only legal to call setBinaryStream on an
empty Blob
Reply all
Reply to author
Forward
0 new messages