-->
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: Blobs contain empty files after update!
PostPosted: Fri Feb 08, 2008 7:52 pm 
Newbie

Joined: Fri Feb 08, 2008 7:07 pm
Posts: 2
Hi, I'm having an issue where blobs contain only an empty file after an update. Another weird thing is that I am not using the cascade option in my mapping file, yet calling save() on the "branch" object causes the "leaf" that it references to be updated as well. The code below is not the actual application, rather a simplified test case to explain what I'm trying to do.

I'm happy to post the full source, mapping files, and debug logs if needed, but this example may be quicker to understand.

The basic idea is that the file is transferred to the local disk, analyzed, and then the object is updated to reflect the results of the analysis.

Thanks!

Hibernate version: 3.2.5

Code between sessionFactory.openSession() and session.close():
Code:
Branch branch = new branch();
Leaf leaf = session.load(Leaf.class, 316L);
branch.setLeaf(leaf);
         
IOUtils.copy(
  leaf.getBlob().getBinaryStream(),
  new FileOutputStream("test.data"));
         
leaf.setColor("green");
         
session.save(branch);



Name and version of the database you are using:
PostgeSQL 8.1.9


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 25, 2008 5:39 pm 
Newbie

Joined: Fri Feb 08, 2008 7:07 pm
Posts: 2
I found a solution to this problem. The class must have
Code:
dynamic-update="true"
set in the hbm.xml.

I believe the reason is without this, hibernate attempts to update the blob even if it hasn't changed. After being read, the blob will contain a stream that has been exhausted, i.e. the pointer is all the way at the end of the stream and can't be reset. So it uploads an empty file, overwriting the original.


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.