• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic