Hi guys...my blobs are (more or less) working fine but I have a question about the syntax.
Generally speaking I'm doing (this is code paraphrase):
Code:
InputStream stream = ...
Blob blob = Hibernate.createBlob(new byte[1]);
BlobTestBean bean = new BlobTestBean();
bean.setBlob(blob);
session.save(blob);
I'm not sure what the second statement does. I've seen different examples on this site, like
Code:
Blob blob = Hibernate.createBlob(stream);
but I get an Exception: Caused by: java.sql.SQLException: Io exception: Software caused connection abort: socket write error
I've also tried
Code:
Blob blob = Hibernate.createBlob(new byte[0]);
but I get a NullPointerException
So I've settled on
Code:
Blob blob = Hibernate.createBlob(new byte[1]);
Because one has to save and then refresh the object to write binary data to a Blob, is there any reason other than calling
Code:
Blob blob = Hibernate.createBlob(new byte[1]);
to create Blob before saving? In the end, all you need to do is save the object, refresh it, get the Blob back (which is now a database specific blob) and write the bytes to it.
Thanks, Steve