Hi i want to create a blob in hibernate from an inputstream, but i don't know the length of the stream.
Hibernate.getLobCreator(sessionFactory.getCurrentSession()).createBlob(stream, length)
how can i crate a blob without knowing the length of the stream?
EDIT1
in older hibernate versions it was possible
http://viralpatel.net/blogs/tutorial-save-get-blob-object-spring-3-mvc-hibernate/
Blob blob = Hibernate.createBlob(file.getInputStream());
EDIT2
ok but it had an buggy implementation
return new SerializableBlob( new BlobImpl( stream, stream.available() ) );
stream.available isn't the real size
EDIT 3
i tried
session.doWork(new Work() {
@Override
public void execute(Connection conn) throws SQLException {
LargeObjectManager lobj = ((org.postgresql.PGConnection) conn).getLargeObjectAPI();
but conn is just a NewProxyConnection from c3p0.
Here is what i'm using now
Session currentSession = getSessionFactory().getCurrentSession();
Blob blob = Hibernate.getLobCreator(currentSession).createBlob(new byte[0]);
OutputStream setBinaryStream = blob.setBinaryStream(1);
Utils.fastChannelCopy(input, setBinaryStream);
setBinaryStream.close();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With