-->
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: PostgreSQL blob (by OID) got trucated after update
PostPosted: Fri Mar 16, 2007 11:44 am 
Newbie

Joined: Sun Sep 12, 2004 3:33 am
Posts: 1
I have found a issue (bug?) that hibernate would truncate blob (by oid) in PostgreSQL after updating the entity, even the code just reading blob binary stream:

Hibernate version: 3.2.1

Mapping documents:
Code:
public class SubjectFile {
   private Long id;
   private Blob data;
   private String filename;
   //omit getter and setter
}

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="antar.acquisition.file" >
   <class name="SubjectFile" table="subject_file" lazy="true" >      
      <id name="id" column="id">
         <generator class="sequence">
            <param name="sequence">seq_subject_file</param>
         </generator>
      </id>      
      <property name="data" not-null="true" /> <!-- blob-->
      <property name="filename" length="255" not-null="true" unique="true"/>      
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
//Read and update in transaction
Transaction transaction = session.beginTransaction();
SubjectFile loadFile = (SubjectFile) session.get(SubjectFile.class, new Long(12));
byte[] readBytes = IOUtils.toByteArray(loadFile.getData().getBinaryStream());
assertEquals(1000, readBytes.length);  // data is 1000 bytes.
loadFile.setFilename("makeSomeChange.txt");

// fileName got updated but blob is truncated to 0 byte at database!
session.saveOrUpdate(reload); 
transaction.commit();
session.close();


Name and version of the database you are using:
PostgreSQL 8.1 with jdbc driver 8.2-504

The generated SQL (show_sql=true):
Hibernate: update subject_file set data=?, filename=? where id=?

Any help on this issue ? should I file a issue on JIRA ?


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.