-->
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.  [ 5 posts ] 
Author Message
 Post subject: Oracle Blob ClassCastExcpetion (I know I know...Just read):(
PostPosted: Thu Sep 15, 2005 6:15 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 3:15 pm
Posts: 29
Okay, I have read until my eyes are bleeding! :)
I read http://www.hibernate.org/56.html
I am using Oracle 9i with jdbc-thin.
I am deploying to SAP's App Server (Stop laughing)
I have an object I am saving. It has a collection of children with a BLOB. I am using the Interceptor (BTQ, nice pattern!!!!) to save the blob.

And of course I get the infamous ClassCastException! I understand that Oracle 9i classes12.jar sucks in that it says it wants a java.sql.Connection but then it barfs even when you give it an OracleConnection.


My question is: Is there a work around to save a BLOB in Oracle 9i thin-jdbc using Hibernate on an App-server?

Hope you all had a good laugh but expert advice at this point would be nice!

Thank you, I love you!
;)
B

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 6:48 pm 
Newbie

Joined: Tue Nov 09, 2004 3:09 pm
Posts: 9
I found this particular section to be helpful for dealing with CLOBs:

http://hibernate.org/56.html#A4

I'm doing this in an App Server and so far no problems. I would hope something similar could be done with Blobs.

--Rob


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 8:37 am 
Beginner
Beginner

Joined: Tue Jun 21, 2005 3:15 pm
Posts: 29
I tried your suggestion this morning and I am STILL getting ClassCastException. :(

I switched the code to Blob. I am going to request we move to Clob and try it again.

I am getting the Cast Exception on an insert on this line:


oracle.sql.BLOB tempBlob = (oracle.sql.BLOB)rs.getBlob(1);



Here is my code
int tempBlobId;

Connection con = st.getConnection();
Statement sta;
ResultSet rs;

String sql = "select seq_temp_blob_id.nextval from dual";

sta = con.createStatement();
rs = sta.executeQuery(sql);
rs.next();
tempBlobId = rs.getInt(1);

rs.close();
sta.close();

sta = con.createStatement();
sql = "insert into temp_blob_table (id, temp_blob) values(" + tempBlobId + ", empty_blob())";
sta.executeUpdate(sql);

sta.close();

sta = con.createStatement();
sql = "select temp_blob from temp_blob_table where id=" + tempBlobId+ " for update";
sta = con.createStatement();
//WHY TWO 'sta = con.createStatement();'????
rs = sta.executeQuery(sql);

rs.next();

BLOB tempBlob = (BLOB)rs.getBlob(1);

OutputStream tempClobWriter = tempBlob.getBinaryOutputStream();
try {
tempClobWriter.write((byte[])value);
tempClobWriter.flush();
tempClobWriter.close();
} catch (IOException ioe) {

rs.close();
sta.close();
throw new HibernateException(ioe);
}

rs.close();
sta.close();

st.setBlob(index, tempBlob);

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 9:11 am 
Beginner
Beginner

Joined: Tue Jun 21, 2005 3:15 pm
Posts: 29
Tried the Clob version also and I still get ClassCastException.
Any thoughts would be helpful....
B

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 7:22 pm 
Newbie

Joined: Thu Jan 19, 2006 7:16 pm
Posts: 5
I had this same problem. I believe if you are using Hibernate 3 and greater, to cast a blob as a Oracle.sql.BLOB you need to call getWrappedBlob() on a hibernate Blob. Here is where I found this: [url]http://www.hibernate.org/250.html#A15[/url]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.