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.  [ 2 posts ] 
Author Message
 Post subject: saving binary to HSQLDB....
PostPosted: Mon Nov 20, 2006 4:54 pm 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.0

Name and version of the database you are using:
HSQLDB

Hello,

There is a small issue I can't seem to be able to solve... In very few words I have to save an image to the database...

I have tried this solution: http://www.hibernate.org/73.html but it doesn't work... first of all HSQLDB doesn't have BLOB as a data type.. so I tried using BINARY but that doesn't work either... it actually saves all the data from the entity but not the image... even dough the data is sent to the nullSafeSet method properly... I changed

return new int[] { Types.BLOB };

to

return new int[] { Types.BINARY };

and replaced

st.setBlob(index, Hibernate.createBlob((byte[]) value));

with

st.setBinaryStream....

but still nothing... I will post the whole class with the modifications I made tomorow...

any ideas ? anybody... ???????

Thank You


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 21, 2006 4:09 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
here is what I modified in the BinaryBlobType class:

Code:
    public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
  throws HibernateException, SQLException
  {
    InputStream input = rs.getBinaryStream(names[0]);
    if (input == null) return null;
    byte [] blob = null;
      try {
          input.read(blob);
          input.close();

      } catch (IOException e) {
          e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
      }
    return blob;
  }

  public void nullSafeSet(PreparedStatement st, Object value, int index)
  throws HibernateException, SQLException
  {
    InputStream is = new ByteArrayInputStream((byte[]) value);
    st.setBinaryStream(index, is,((byte[]) value).length);
  }


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