-->
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.  [ 7 posts ] 
Author Message
 Post subject: Binary data
PostPosted: Tue Nov 25, 2003 2:07 pm 
Beginner
Beginner

Joined: Wed Oct 08, 2003 6:34 am
Posts: 29
Hi there,

I'm trying to store binary data in my database with no success. Basically I have the following:

Code:
  public byte[] getContent(  )
    {
    return this.content;
    }

Code:
        <property name="content" type="binary" update="true" insert="true"
            column="content" length="1073741824" unique="false"/>


I use the tool included with hibernate to generate the schema in an Oracle database, and this column gets mapped to a LONG RAW.

When I try to store data in this column I get an SQLException telling me that the size of the data is greater than the allowed size for this type. I think this is caused by the Oracle driver, so I have set the hibernate.jdbc.use_streams_for_binary property to true as told in the documentation with no success. Should I change anything else? Or should I forget about using byte[] and use Blob in my code (something I would like to avoid)?

Regards


Top
 Profile  
 
 Post subject: 1 Gig!?
PostPosted: Tue Nov 25, 2003 3:24 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Quote:
length="1073741824"


Is that truely the length of your field!? I don't think you can define a field that is 1Gig (unless I misread) in length.

Quote:
and use Blob in my code (something I would like to avoid)


What's wrong with Blob? I think that is the only way you are going to be able to store a Gig of binary data. After all, a Blob is just binary data effectively is it not?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 5:35 pm 
Beginner
Beginner

Joined: Wed Oct 08, 2003 6:34 am
Posts: 29
I let hibernate generate automatically my schema, so if I don't put length, or put a short length, hibernate generates a RAW column with a fixed length. I just put this length to force hibernate to generate a LONG RAW column. In Oracle a LONG RAW column is able to store binary data of variable length up to 2Gb.

There is nothing wrong with using blob in the database, but as far as I know, if you use it, hibernate wants a java.sql.Blob in the corresponding java property. Maybe I'm wrong regarding this, but I would like to keep my java code as free as possible of SQL related stuff, so if in the future I want to migrate to, let's say, JDO, the impact is minimal (by the way, I don't know anything about JDO).

Maybe I wasn't clear in the last post. The question is... how can I persist binary data with hibernate supposing I want to have a java property of type byte[] or InputStream, but not Blob? Is this possible?

Regards
Jose


Top
 Profile  
 
 Post subject: Re: 1 Gig!?
PostPosted: Tue Nov 25, 2003 6:48 pm 
Newbie

Joined: Tue Nov 25, 2003 5:05 pm
Posts: 18
DavidNDuffy wrote:
Quote:
and use Blob in my code (something I would like to avoid)


What's wrong with Blob? I think that is the only way you are going to be able to store a Gig of binary data. After all, a Blob is just binary data effectively is it not?


It depends what kind of blob field you have and what you want to do with the blob field. In the database a blob field is quite different in comparision to "ordinary" fields like int, char, varchar. Blobs are usually saved in different locations with different storage methods, use different buffer management, are manipulated different, are different between databases etc.
I would not use blobs with hibernate unless I know exactly how hibernate handles blobs. There are quite a bit of concepts how to deal with blobs efficiently that are not avaliable with hibernate (e.g. locator).

ciao
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 29, 2005 9:04 am 
Newbie

Joined: Wed Dec 08, 2004 8:56 am
Posts: 12
Location: China ChengDu
hi jgongo

any news in the end ? I meet the problem also.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 29, 2005 3:08 pm 
Beginner
Beginner

Joined: Wed Oct 08, 2003 6:34 am
Posts: 29
I seem to remember that I finally used some JDBC code to handle BLOB fields, but I'm talking from the top of my mind... man, that happenned more than a year ago :o)

Anyway, I would take a look at the wiki pages in the hibernate site, and maybe repost the question... I guess the situation may be different, specially taking into account that you now have the new shining Hibernate3 in beta2 version.

Best regards, and good luck
Jose


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 29, 2005 11:17 pm 
Newbie

Joined: Wed Dec 08, 2004 8:56 am
Posts: 12
Location: China ChengDu
hi jgongo:
Yes, your right! When i used PreparedStatement.setBinaryStream(2,in,in.available()), the problem solved. But i want use Hibernate not JBDC code, waiting for somebody explain WHY?

THX
rosen


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