-->
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: Zero Length Blobs
PostPosted: Mon Aug 15, 2011 8:24 pm 
Newbie

Joined: Mon Aug 15, 2011 8:09 pm
Posts: 3
I am attempting to resolve an issue with inserting empty blobs. We originally had our blobs mapped to byte[] but when storing a byte[0] hibernate considers this a null and then the insertion fails. We switched to using java.sql.Blob which resolved the problem until we added Apache Derby to the mix. Derby's blobs are only valid till the end of the transaction which isn't compatible with our existing code. I was reading about using a Hibernate User Type to act as some kind of middle man between blob and byte[] but I am not sure if this is appropriate. I also do not understand how to use a Hibernate user type.

Does anyone have a better way to deal with blobs that can be of zero length? Is a Hibernate User Type the proper solution? Should I really be only handling blobs in transactions and refactor the entire codebase (Please say no)?

Regards,
Thomas


Top
 Profile  
 
 Post subject: Re: Zero Length Blobs
PostPosted: Tue Aug 16, 2011 1:25 pm 
Newbie

Joined: Mon Aug 15, 2011 8:09 pm
Posts: 3
I ended up copying a merge of PrimitiveByteArrayBlobType and ByteArrayBlobType that does not use streams. Then annotate the blob member with

Code:
@Lob
@Type(type="com.example.PrimitiveNoStreamByteArrayBlobType")
private byte[ ] myCol;


I tried just modifying the dialect to return false to Dialect.useInputStreamToInsertBlob() but WrappedMaterializedBlobType does not seem to obey this. I am not sure if it uses some other method that is neither stream not setBlob but it doesn't work.

Regards,
Thomas


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.