Saving Big Binaries using ORM

I was having a problem getting a binary/blob column started up in a ColdFusion app I’m working on that uses Hibernate to do the ORM stuff.

At first, I used “blob” for the sqltype attribute, but that just created a small, 255 byte column once the ORM was refreshed. This is what didn’t work…

property 
  name = 'myBinaryFileProperty'         
  column="myBinaryFileColumn"            
  sqltype="blob";

So I did some searching and decided to try setting the sql type to “varBinary”…

property 
  name = 'myBinaryFileProperty'         
  column="myBinaryFileColumn"            
  sqltype="varbinary(max)";

This created a column that accepted a large binary entry (score one goal), but I got an error in the Base.cfc file when trying out the code…

message: Property : myBinaryFileProperty – ByteArray objects cannot be converted to strings.
detail: Root cause :org.hibernate.HibernateException: Property : myBinaryFileProperty – ByteArray objects cannot be converted to strings.
file: Base.cfc
line: 80
path: \pathTo\model\beans\Base.cfc

This error pointed to a line that was simply doing an “ormFlush()”.  Instead of getting into that, I decided to change up the attributes and see if I found something that worked.

I decided to try and add the “type” attribute, and thought that may help the ORM to know how to handle that property correctly.  Maybe that’s why it worked, but I don’t know.  This is what worked…

property 
  name = 'myBinaryFileProperty'         
  column="myBinaryFileColumn"            
  type="binary" sqltype="varbinary(max)";

I never found anything that addressed this, in a good way, while web-searching, so I decided to throw up a blog post about it.

My db backend was MS-SQL, and almost certain the app server was ColdFusion 9.

Caveat: I used poor variable names for the purposes of making sure you could understand the code.

Advertisements

About this entry