-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to update blob column in hibernate
PostPosted: Thu Nov 01, 2012 3:44 am 
Newbie

Joined: Thu Nov 01, 2012 3:00 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.