Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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

Ranch Hand
Posts: 1249
Spring Java 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
TITLE *************************varchar(255)
EVENT_ID *************************bigint(20)

Here are my configuration files.

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!!!
[ May 20, 2008: Message edited by: Ankur Sharma ]
Shaan Shar
Ranch Hand
Posts: 1249
Spring Java 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.
Did you just should on me? You should read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic