-->
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.  [ 3 posts ] 
Author Message
 Post subject: Web Services and Oracle BLOB
PostPosted: Thu Oct 16, 2003 5:34 pm 
Newbie

Joined: Thu Oct 16, 2003 5:30 pm
Posts: 3
I'm using Hibernate as the persistance layer for a Web Service through EJBs. I have some columns that are Oracle BLOBs but all I want the user to see is a String. I wrote a custom user type which maps the Blob to a String, and for retrieval of data it works correctly. However, when I try to update or insert I get a cast exception insice the oracle driver. It seems that Hibernate.createBlob creates a hibernate blob instance while OraclePreparedStatement.setBlob requires oracle.sql.BLOB.

Does anyone have any experience solving this problem? Do I just have to create an Oracle BLOB explicitly and ignore cross database functionality?

The custom class is below:

************ BEGIN CODE ******************
public class BlobString implements UserType {
public int[] sqlTypes() {
return new int[] { Types.BLOB };
}

public Class returnedClass() {
return String.class;
}


public boolean equals(Object x, Object y){
return x.equals( y );
}

public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException {

Blob blob = rs.getBlob(names[0]);
if ( null == blob )
return null;

byte bytes[] = blob.getBytes( 1 , (int)blob.length() );
String data = new String(bytes);

return data;
}

public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {

byte bytes[] = ((String)value).getBytes() ;

st.setBlob( index, Hibernate.createBlob( bytes ) );
}

public Object deepCopy(Object value) {
if (value == null)
return null;

return new String ( (String)value ) ;
}

public boolean isMutable() {
return true;
}

}

************ END CODE *******

This is the error Message:

java.lang.ClassCastException
at oracle.jdbc.driver.OraclePreparedStatement.setBlob(OraclePreparedStatement.java:1446)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setBlob(WrappedPreparedStatement.java:680)
at com.doubleclick.util.BlobString.nullSafeSet(BlobString.java:47)


Thanks for your help.
-Eliot


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 19, 2003 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate.createClob() is for use with a property of type "clob" ONLY!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 20, 2003 10:20 am 
Newbie

Joined: Thu Oct 16, 2003 5:30 pm
Posts: 3
I used Hibernate.createBlob(), not Clob.

I was able to work areound it by using
st.setBytes - though I'm not sure this will work with all Databases.


gavin wrote:
Hibernate.createClob() is for use with a property of type "clob" ONLY!!


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