-->
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.  [ 7 posts ] 
Author Message
 Post subject: Problems with blobs on PostgreSQL
PostPosted: Sat Sep 27, 2003 4:06 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 4:19 pm
Posts: 42
I've searched older threads on this issue and see that people have successfully set up blobs on PostgreSQL, but I've tried to replicate and haven't had any luck. I'm trying to store image files in a blob column and have tried the following hbm mappings/tabledefs with no luck:

Postgre datatype bytea w/ Hibernate types binary (throws a CGLIB exception on startup) and blob (Postgre throws a "bad integer" exception on flush).

Tried Postgre datatype OID with Hibernate blob (no exceptions, but no data gets written) and binary (throws ClassCastException net.sf.hibernate.type.BinaryType.deepCopyNotNull)

The java code to do the write is below. Any help would be much appreciated

InputStream stream = file.getInputStream();
Session session = HibernateListener.open(request);
ManageUserService.ManageUser mu = ManageUserService.getManageUser();
User user = mu.getUserById(userid, session);
Blob photo = Hibernate.createBlob(stream);
user.setPhoto(photo);
session.flush(); //this is where it bombs out
session.connection().commit();
session.close();


Top
 Profile  
 
 Post subject: seems...
PostPosted: Sun Sep 28, 2003 9:22 pm 
Regular
Regular

Joined: Wed Sep 03, 2003 8:04 am
Posts: 55
user.setPhoto(photo);
session.flush(); //this is where it bombs out
sess.save(user);session.connection().commit();
session.close();


regards!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2003 7:32 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 4:19 pm
Posts: 42
Just to follow up so nobody else has to go through the aggravation that I did with this....

With the current PostgreSQL JDBC driver, there is no way for Hibernate to talk to PostgreSQL blobs. You have to use the native LargeObject API, which stores the blobs in a special system table (pg_largeobject). The only way to associate it with your Hibernate entities is to create an integer field and store the UID of the blob there. To retrieve, load up your hibernate entity object, retrieve the blob id, then retrieve the blob through straight JDBC and the LargeObject API.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 29, 2003 7:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is probable that you could do at least some of this work in a UserType.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 10:59 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Hmmmm......

Any suggestions on how to create that UserType. I just had to convert to postgresql and discovered this problem about five minutes ago. :(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 11:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Learn how to do it by writing code using direct SQL/JDBC, and then figure out how to re-implement that using a UserType.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 1:35 am 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Ah, it's a non-issue now. I'm using binary instead of blob, which works like a champ for my purposes. I don't think it would have been too hard to hard to rewrite the BinaryBlobType example from http://www.hibernate.org/73.html, though.


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