-->
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.  [ 6 posts ] 
Author Message
 Post subject: About use Hibernate2 to access a Blob type column in ORACLE
PostPosted: Tue Sep 09, 2003 4:27 am 
Newbie

Joined: Fri Aug 29, 2003 6:40 am
Posts: 2
The database I'm using is ORACLE 9.2.
I got an ClassCastExceptiontyied when trying to use Hibernate2 to
insert records to a table which contains Blob type columns.
It seems that hibernate2 is trying to use the setBlob method of
java.sql.PreparedStatement class. But the implementation of
ORACLE seems to cast the inputted Blob object into a ORACLE
specified Blob type object immediately.
That's why it leads to an ClassCastException.

My question is, does this mean that I cannot use that hibernate
to write a Blob type object to the ORACLE database at all?
Or there are some ways to avoid this problem?

By the way, as the cause of the problem is the implementation
of the setBlob method, it means that I cannot avoid this problem
even when I use JDBC directly.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2003 4:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I don't know WHAT you're doing, but if you use it as is intended, ie use type="blob", Hibernate will not call setBlob() when it is an instance created with Hibernate.createBlob(). It will call setBinaryStream() instead.


Top
 Profile  
 
 Post subject: About use Hibernate2 to access a Blob type column in ORACLE
PostPosted: Tue Sep 16, 2003 3:47 am 
Newbie

Joined: Tue Sep 16, 2003 3:41 am
Posts: 1
I have the same problem. I used the "Mapping a Blob to a byte[]"-solution
(http://hibernate.bluemars.net/73.html) and therefore have type="com.netikos.se.storeimpl.BinaryBlobType".


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 16, 2003 1:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, here is a comment (by me), from the bottom of the page:
a mutable object.

Quote:
The use of setBlob() will work on some drivers, but not all. I think its more portable to use setBytes() or even setBinaryStream().


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 17, 2003 5:55 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
I try to use byte[] <-> Blob also.
DB : PostgresSQL 7.3.1 under Linux

My table is

create table external_docs (
ext_id int4 not null,
report_id int4 null,
name varchar(200) not null,
value bytea not null,
content_type varchar(100) null,
create_date timestamp null,
constraint pk_external_docs primary key (ext_id),
constraint fk_external_relations_report foreign key (report_id)
references report (report_id)
on delete restrict on update restrict
);

I used original BinaryBlobType example and modificated :
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
final byte[] buf = (byte[]) value;
ByteArrayInputStream in = new ByteArrayInputStream(buf);
st.setBinaryStream(index, in, buf.length);
}

But still i'm getting errors like this one:
Hibernate: select nextval ('ext_doc_seq')
Hibernate: insert into external_docs (name, content_type, value, report_id, create_date, ext_id) values (?, ?, ?, ?, ?, ?)
13:48:17,098 WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: null
13:48:17,098 ERROR JDBCExceptionReporter:46 - ERROR: column "value" is of type bytea but expression is of type integer
You will need to rewrite or cast the expression


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 17, 2003 6:36 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
I've fixed this problem.
Using type="binary" and downloading the lastest version of jdbc drivers.


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