Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic