-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to read or write Blob(BLOB) object
PostPosted: Mon Jan 09, 2006 2:55 am 
Newbie

Joined: Sun Jan 08, 2006 11:58 pm
Posts: 2
When I use Hibernate write a Image into database(Oracle10g)
MY code like these,but when I run it ,it has ClassCastExcetiion
(Blob blog=(BLOB)tp.getTp())
the type of tp.getTp() is Blob


/**
*
* @param filename String
* @param tp TuPian
* @throws FileNotFoundException
* @throws IOException
*/
public void addTuPian(String filename, TuPian tp) throws
FileNotFoundException, IOException, SQLException, HibernateException {
byte[] buffer = new byte[1];
try {
session = sessionFactory.openSession();
transaction = session.beginTransaction();
tp.setTp(Hibernate.createBlob(buffer));
session.save(tp);
session.flush();
session.refresh(tp, LockMode.UPGRADE);
BLOB blob =(BLOB) tp.getTp();
// out =blob.getBinaryStream();
File file = new File(filename);
FileInputStream infile = new FileInputStream(file);
byte[] data = new byte[ (int) infile.available()];
infile.read(data);
infile.close();
session.flush();
transaction.commit();
}
catch (HibernateException e) {
if (null != transaction) {
transaction.rollback();
e.printStackTrace();
}
}
finally {
session.close();
}
}


Top
 Profile  
 
 Post subject: Re: How to read or write Blob(BLOB) object
PostPosted: Mon Jan 09, 2006 10:03 pm 
Newbie

Joined: Sun Jan 08, 2006 11:58 pm
Posts: 2
Who can help me??
I am worry about it for four days!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 7:42 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 4:20 am
Posts: 40
Location: Vienna
Hi,

note that there are two different types of Blobs:

java.sql.Blob: the Java standard Type
oracle.sql.BLOB: the oracle driver's type

It seems to me that you cast from one to the other
(In your code, you write sometimes BLOB, sometimes Blob)



Anyway, I have not yet managed to read a blob from an Oracle database using Oracle's DB driver - it is simply too buggy.
The only driver that worked so far was the Oracle driver by DataDirect
(http://www.datadirect.com)

However, this one is not really cheap...

regards,
Stefan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 11:42 am 
Beginner
Beginner

Joined: Tue Jul 05, 2005 4:44 am
Posts: 40
Location: Paris, France
I advice you to read http://www.hibernate.org/56.html (Using Clobs/Blobs with Oracle and Hibernate)

Personnaly, I used the driver 10g with a Oracle 9.02 and I works good.

_________________
Fred


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

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.