[hibernate-users] mysql blob issues
James Norman
james.norman at gmail.com
Thu Apr 17 16:57:55 EDT 2008
Hello All,
I've been using hibernate with mysql for a while now with great success. I
searched everywhere and could not find a solution to this problem, so thanks
for any support you can provide.
I'm currently storing some data as a byte[] in an object and stored in the
mysql database as a blob. This was seamless with hibernate and had no
issues. I need to now deal with the data as a stream as it's bad form to
carry a 5mb byte[].
I added the methods to the object :
java.sql.Blob getBlob() and setBlob( java.jql.Blob)
and added the :
<property name="blob" type="binary" /> (tested with and without the
type="binary")
I get the following error if I don't set the blob (would be null)
And I recreate the DB each time. I get the following error when inserting
the object:
Hibernate: insert into AUDIO (bytes, name, contentType, blob) values (?, ?,
?, ?)
Exception in thread "main" org.hibernate.exception.SQLGrammarException:
could not insert: [com.polling.Audio]
Caused by: java.sql.SQLException: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right
syntax to use near 'blob) values
(_binary'\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', null, null, nul' at line
1
And I get the following error if I do set the blob with a simple:
audio1.setBlob( Hibernate.createBlob( new byte[1] ) );
Exception in thread "main" java.lang.ClassCastException:
org.hibernate.lob.SerializableBlob
Environment:
Windows Xp sp2
java 1.5.0_04
Mysql 5.0.20-nt
Hibernate 3.2
Thanks again for any help.
-james
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-users/attachments/20080417/8a7e5eb6/attachment.html
More information about the hibernate-users
mailing list