• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 1252
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1252
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You didn't tell me he was so big. Unlike this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic