Hi,
Could you please tell me the way to how to get the outputstream from blob and write to it using hibernate I want to achieve below task using hibernate. I am inserting empty blob first and then updating the blob and finally committing it.This works perfectly fine.
con = DriverManager.getConnection(url, username, password); stmt = con.createStatement();
sqlText = "INSERT INTO table1 (file_name, file) " + " VALUES('" + fName + "', EMPTY_BLOB())"; stmt.executeUpdate(sqlText);
sqlText = "Select file from table2 where file_name='" + fName + "'" + "FOR UPDATE"; rset = stmt.executeQuery(sqlText);
rset.next(); blob = (BLOB) rset.getBlob("file"); outStream = blob.setBinaryStream(0L);
//I write to this outstream and finally con.commit();
************************************************************** I tried below in hibernate code but I am not sure whether it is correct or not..
Table1 file = new Table1(); file.setFileName(fileName); file.setBlobFile(Hibernate.createBlob(new byte[1])); session.save(file); session.flush();
session.refresh(file, LockMode.UPGRADE);
Blob blob = null;
if (file.getId() != 0) { blob = file.getBlobFile();
outStream = blob.setBinaryStream(0L);
} inputStream = new FileInputStream("test.txt");
IOUtils.copy(inputStream, outStream);
session.saveOrUpdate(file); transaction.commit();
But it throws me below error at session.saveOrUpdate(file);
[IOException ]java.io.IOException: ORA-22990: LOB locators cannot span transactions.
Could anyone please help
|