I'm looking for a way to directly write a blob on an entity using an OutputStream. I don't know the size of the data in advance, so I need the OutputStream way of doing it.
I've already tried:
Code:
@Lob
@Column(length = 10 * 1014 * 1024)
@Basic(fetch = FetchType.LAZY)
private Blob document;
public OutputStream getDocumentOutputStream(EntityManager entityManager) throws SQLException {
HibernateEntityManager hibernateEntityManager = entityManager.unwrap(HibernateEntityManager.class);
Session session = hibernateEntityManager.getSession();
LobHelper lobHelper = session.getLobHelper();
this.document = lobHelper.createBlob(new byte[0]);
session.save(this);
session.flush();
session.refresh(this);
return this.document.setBinaryStream(1);
}
Writing to the
OutputStream I get from
getDocumentOutputStream(entityManager) works on H2 and MySQL, but not from within JBoss EAP 6.3.2 using MySQL (Arquillian integration test). Is this a bug in that version of Hibernate?