Announcement Announcement Module
No announcement yet.
Strange Blob Problem - Ends Up Entirely Corrupted? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strange Blob Problem - Ends Up Entirely Corrupted?


    I'm using spring and hibernate, and have a strange blob problem. I use Xdoclet and map a blob field into the DB with a normal:

    mapping, and this generates by blob table field and all is good. I can store normal data in there, and don't have any problems... until I try to store encrypted data.

    I have an application that stores normal data in some blobs (text, file data, etc..) and encrypted data in some blobs (the raw encrypted output). The problem is.. when I store the raw encrypted data, it silently fails and stores the data as a totally munged data.

    The odd thing.. when I store it, lets say I'm storing a byte array of 208 bytes.. if a select length(blobfield) from the database, it says 208 bytes.. but when I read that blob back in its 104 bytes.

    Now.. if I simplify the encoding of the data by, say, Hex encoding it before storing it in the blob... no problem. It stores fine, and retrieves fine.

    Now, I use this Blob handler all over my app, and this is the only place I have this problem. Any ideas on what the heck is going on?

    By the way, this is with a MySQL 4 database and blob/longblob fields. I'm using an INNODB backend, and Hibernate / Spring's Blob handlers in this application.

    Any pointers would be great! Thanks!

  • #2
    It's clearly a problem with your db settings. Most probably your blob contains 2 bytes character in encrypted format and mysql uses only 1 byte format for storage. See what are mysql options for storing binary/raw format (from my experience I know they tend to do things their own way).

    If possible try also other database (like postgresql) and see how it handles the problem - this way you can figure out how to store your encrypted information in a common format that will work on most dbs.


    • #3
      Thats my thinking..

      I would agree.. I haven't tried another DB, though I will be due to my requirements anyway.. but I wanted to see if anybody else has had this problem in storing the raw bytes through the Spring/Hibernate layer.

      I've used Hibernate for storing BLOB's in the past, but without Spring's layer on top of that. I wanted to see if I was doing something odd in that interaction, but the spring code seems pretty straightforward in that area.

      I store other blobs in the same application, but without a problem. I guess this is a post for the MySQL forums..



      • #4
        I suggest then to seek the differences between your previous HB code and the one in Spring. Probably you have the HB's data source configured different or maybe the session factory (though less likely).
        This happens especially because many people switch to Commons-DBCP w/ Spring from c3p0.