I have an application which is trying to save a photo to the database. I’ve created a grails domain class with a byte[] property and this was working well when using HSQLDB (the default in grails). However, when I changed the database to MySQL I ended up getting the following error:
Data truncation: Data too long for column 'photo' at row 1
I then had a look at the schema and found that the byte[] was being created as a TINYBLOB field, which was causing the error.
How can I specify that this property should correspond to a BLOB/LONGBLOB type in the database?
You should be able to manage that by adding a
mappingclosure a bit like this:Documentation is here: http://grails.org/doc/latest/ref/Database%20Mapping/type.html
Hibernate types are here: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-types-basictypes
There’s also a
sqlTypeproperty, which I believe refers to the underlying database type, rather than hibernate’s database agnostic type abstractions:Documentation for this is here:
http://grails.org/doc/latest/ref/Database%20Mapping/column.html