• 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

Hibernate and Blobs...@Lob does no good. Suggestions?

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All I want to do is store and retrieve an image file using Hibernate into a MySQL database. Getting this to work though is proving to be a bit of an issue.

According to Hibernate Made Easy, I should be able to annotate the image field with @Lob. Well, I tried that and I still get the same exception when I run my code:

18:56:10,775 DEBUG DefaultIdentifierGeneratorFactory:90 - Setting dialect [org.hibernate.dialect.MySQLDialect]
Exception in thread "main" org.hibernate.MappingException: Could not determine type for: com.mysql.jdbc.Blob, at table: Item, for columns: [org.hibernate.mapping.Column(image)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:306)
at org.hibernate.mapping.Column.getSqlTypeCode(Column.java:164)
at org.hibernate.mapping.Column.getSqlType(Column.java:208)
at org.hibernate.mapping.Table.sqlCreateString(Table.java:418)
at org.hibernate.cfg.Configuration.generateSchemaCreationScript(Configuration.java:1067)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:131)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:92)

The funny thing is I don't even have the Blob set up as a com.mysql.jdbc.Blob object but I guess it infers that given the dialect it chooses.

Here is what a snippet of file looks like:


@Lob //Indicate to Hibernate that this is a type of Blob/Clob object
private java.sql.Blob image;


So, just how does one create/read an image file using Hibernate on a MySQL database? I see somewhere someone posting a fairly extensive amount of code but surely there is an easier way isn't there?

Thanks!
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Lob does work at least for table creation (we will see when it comes to the real thing of reading/writing). There was another image it was griping about that I didn't have annotated.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic