File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Read/Write BLOB in byte[] with Hibernate in MySQL.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Read/Write BLOB in byte[] with Hibernate in MySQL.." Watch "Read/Write BLOB in byte[] with Hibernate in MySQL.." New topic
Author

Read/Write BLOB in byte[] with Hibernate in MySQL..

Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Hi Team,

I am using hibernate with MySQl(Mysql-5.0.5). I have a table with a column type BLOB. Corresponding bean in java has byte[] for this column. I am able to write blob sucessfully but not able to read the blob in byte[].


My Table(Person) looks like this
------------------------------------------
Field *************************Type
------------------------------------------
PERSON_ID *************************bigint(20)
age *************************int(11)
firstname *************************varchar(255)
lastname *************************varchar(255)
BYTE_DATE *************************blob
EVENT_DATE*************************datetime
TITLE *************************varchar(255)
EVENT_ID *************************bigint(20)
------------------------------------------



Here are my configuration files.
Hibernate.cfg.xml


Bean Configuration File is


My Bean Person is


Here is the code which I am trying to run is


Please let me know, if any other details are required...

Any help would be greatly appreciated!!!
Thanks
[ May 20, 2008: Message edited by: Ankur Sharma ]

The Best way to predict your future is to create it - Every great individual common man
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Ok one update from my side.

As I have already mentioned, I was able to write the blob in database.

I am also able to read blob in byte[] but when I am trying to cast it in my bean, it's giving me following exception

java.lang.ClassCastException: [Ljava.lang.Object; incompatible with events.Person


I have changed my bean(Person) and Hibernate.cgf.xml as follows.





Only change in above hibernate.cfg.xml is opting my own defined MySQLDialect. Here is my custome defined MySQLDialectExtended



Could anybody spare a little bit time on this problem and let me know, why t's still not automatically casting result in Person bean.

Any light would be appreciated.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read/Write BLOB in byte[] with Hibernate in MySQL..