-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate.createBlob(InputStream) discussion
PostPosted: Wed Mar 19, 2008 3:35 pm 
Newbie

Joined: Wed Mar 19, 2008 3:20 pm
Posts: 1
Location: Ft. Lauderdale, FL
Hi,

Whilst trying to insert a streaming Blob into MySQL (I'm an optimist), I've got code similar to:

InputStream is = conn.getInputStream(); // From a URL Connection
setMyBlob(Hibernate.createBlob(is));

Trouble is, only a buffer full actually arrives in the database. The JDBC 4.0 spec is a little hazy on actual virgin Blob implementation, but I've tracked down why.

Hibernate does this:
>> src/org/hibernate/Hibernate.java:379
Code:
    public static Blob createBlob(InputStream stream) throws IOException {
        return new SerializableBlob( new BlobImpl( stream, stream.available() ) );
    }


Shouldn't use stream.available(), as it's not the whole story.

Then MySQL does this:
src/com/mysql/jdbc/PreparedStatement.java:2800
Code:
    public void setBlob(int i, java.sql.Blob x) throws SQLException {
...
            bytesOut.write('\'');
            escapeblockFast(x.getBytes(1, (int) x.length()), bytesOut, (int) x
                    .length());


I'm generally leaning towards this not being a MySQL fault, because Hibernate should not be reporting the length of the data if it hasn't been explicitly told it, or properly determined it. I'd like to start a discussion, before filing a bug, on the best approach.

I suggest if the source is a stream then Hibernate either has to fully materialize it to determine length, or throw an unsupportedSQL exception on that method. If this is done, then MySQL should trap the exception and stream the input itself.

Anyone?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.