-->
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.  [ 1 post ] 
Author Message
 Post subject: using Blob, SQLException Bad Integer when gets data, save OK
PostPosted: Thu Nov 17, 2005 8:51 pm 
Newbie

Joined: Wed Nov 09, 2005 11:03 am
Posts: 5
Hi,

I have problem getting data from postgresql database using BLOB.

I'm using hibernate, jdbc-driver, postgresql.

I succesfully insert my large object into database:

Code:
Message message = new Message();
      
File file = new File("jude.ico");
      
InputStream in = null;
      
byte[] tmp = new byte[512];
      
ByteArrayOutputStream out = null;
      
try {
   in = new FileInputStream( file );
         
   out = new ByteArrayOutputStream();
   
   int bytesRead = in.read(tmp);
   while(bytesRead != -1) {
      out.write(tmp, 0, bytesRead);
      bytesRead = in.read(tmp);
   }
} catch (FileNotFoundException e) {
} catch (IOException e) {
}

byte[] data = out.toByteArray();

ByteArrayInputStream byteInput = new ByteArrayInputStream(data);
      
message.setData( data );
      
messageDao.saveOrUpdate( message );


My messageDao.saveOrUpdate( message ) is like this:

Code:
session = HibernateUtil.getSession( userRole );
session.saveOrUpdate( message );
HibernateUtil.commit( session );


Mapping file:
Code:
<hibernate-mapping>
   <class name="mypac.Message" table="message">
         .......

      <property name="dataBlob">
         <column name="message" sql-type="bytea" length="10024"/>
      </property>
      
   </class>


It insert data to database. I can read it from phppgadmin, it is something like: \000\000\001......

But when I call in next line for:
Code:
List messages = messageDao.findAll();


whitch make something like this:
Code:
session = HibernateUtil.getSession( userRole );
messages = session.find( "FROM Message m" );
HibernateUtil.commit( session );


I get exception:
DEBUG - SQLException
org.postgresql.util.PSQLException Bad Integer \000\000\001......


I read a lot of Blob/Clob using Postgresql and hibernate but I donot find answer what is worng.

I also tryied to create BinaryBlobType:
public class BinaryBlobType implements UserType and use it like a type in mapping file, but i get: ERROR: cross-database references are not implemented


Please help me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.