Hi,
I'm saving a Blob in the database, it's all working fantastically. I get a stream from a web service, embed it in a Blob object, then call "save(hibernateObjectWithBlob)". What I would like to be able to do it get the length of the stream/Blob and save it to the database.
I figured that I could do this by (all in one transaction):
1.) Create a new hibernate object in the database
2.) Set the blob as an attribute on the object
3.) Save the object
4.) Intercept the stream's read calls to work out how long the stream is
5.) Set the length of the stream as an attribute on the hibernate object from step 1
6.) Call an update on the object from step 1
This didn't work to plan - I'm getting the correct length of the object I'm interested in, but can't seem to put the value into the database. I believe this is due to the fact that the stream is not being read until one of the later phases of the transaction, after all normal object commits have completed.
I also tried changing the algorithm so the update for the length happens when the stream is closed... but again same problem, the call on the hibernate object is happening at one of the later parts of the transaction and doesn't filter down to the database.
That being considered - is there an easier way to do what I want... seems awfully hard for what should be a trivial task.
Cheers,
Dave
|