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.  [ 8 posts ] 
Author Message
 Post subject: updating an image into database Blob field
PostPosted: Mon Oct 04, 2004 4:11 am 
Newbie

Joined: Wed Sep 15, 2004 6:56 am
Posts: 1
Hi all
I am a new user of Hibernate I am using the hibernate-2.1 version
i am able to map all the column in the db and also can retrive the image
but a problem of updating an image inyo db for I used the seession.update method,but the image is not updated rest of the fields are updated.session=openSession();
Blob b1 = Hibernate.createBlob(picc);
Transaction t = session.beginTransaction();
PatientFinding pfgs = (PatientFinding)session.load(PatientFinding.class,fdi);

pfgs.setFindingsText(finding);
pfgs.setLastUpdatedDate(d);
pfgs.setFindingsImage(b1);
session.update(pfgs);
t.commit();
session.close();

in the above code picc is a byte array
is there is any thing wrong?
if any body know the answer please help me,if possible please give the correct code for inserting the image,and is there any change in the mapping file
I had generated it using middlegen.


Top
 Profile  
 
 Post subject: having the same problem
PostPosted: Wed Jan 17, 2007 2:01 pm 
Newbie

Joined: Thu Jan 11, 2007 1:57 pm
Posts: 9
hi!
i have the same problem. did you fixed it? i have tried but it does not work. hibernate persist the image but if i update the entity encapsulating the image, all other properties become updated but not the image. i set cascade for all actions (persist, merge, refresh and remove).

please, help!


Top
 Profile  
 
 Post subject: Re: having the same problem
PostPosted: Fri Jan 25, 2008 1:05 am 
Newbie

Joined: Thu Jan 24, 2008 1:24 am
Posts: 3
could you send me your code for displaying image in jsp so that i can solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2008 1:01 am 
Newbie

Joined: Thu Oct 25, 2007 5:24 pm
Posts: 12
fast forward to Nov 2008 and Hibernate 3.2, I'm unable to update the blob as well. No problems inserting new rows with blob images.

Code:
@Column(name="MIME_TYPE", length=35, nullable=false)
private String mimeType;
   
@Lob // 500Kb
@Column(name="IMAGE", length=510000, nullable=false)
private Blob image;
   
@Lob //30kb
@Column(name="THUMBNAIL", length=30000, nullable=false)
private Blob thumbNail;


here's how i set the blobs from an incoming MultipartFile
Code:
MyImageEntity(org.springframework.web.multipart.MultipartFile image){
InputStream sourceStream = image.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageUtil.resize(400, "JPEG", sourceStream, out);
byte[] resizedBytes = out.toByteArray();
image = Hibernate.createBlob(resizedBytes);
      
ByteArrayInputStream resizedByes2 = new  ByteArrayInputStream(resizedBytes);
out = new ByteArrayOutputStream();
ImageUtil.resize(100, "JPEG", resizedByes2, out);
thumbNail = Hibernate.createBlob(out.toByteArray());


Why won't hibernate update the blob itself with update() or merge() ? Other columns do get updated however (mimeType for example)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2009 7:23 pm 
Regular
Regular

Joined: Mon Aug 22, 2005 1:11 pm
Posts: 50
Location: Pasadena, CA
I am having a simial problem. I have a list of blobs:

@CollectionOfElements(fetch=FetchType.LAZY)
public List<Blob> extendedKeystrokeDataPerm;

I set the list of the blobs but when I update the object nothing is saved.

Any help would be great appreciated.

Thanks,
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2009 10:34 am 
Newbie

Joined: Thu Oct 25, 2007 5:24 pm
Posts: 12
I ended up having to delete the entity and create new one. I'm sure that's what you wanted to hear :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2009 2:52 pm 
Regular
Regular

Joined: Mon Aug 22, 2005 1:11 pm
Posts: 50
Location: Pasadena, CA
Quote:
I ended up having to delete the entity and create new one. I'm sure that's what you wanted to hear :)


Yeah, thats exactly the solution I was hoping for.

Thanks for replying!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2009 5:26 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
It's important to understand what a BLOB is. It's not a typical database column, it's more or less a pointer to binary data that is read from and written to using streams. Look at the methods:

http://java.sun.com/j2se/1.5.0/docs/api ... /Blob.html

On most databases (all?) you can only use these methods inside the boundaries of a transaction.

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


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