I was having trouble mapping a byte array to a MySQL database in Hibernate, and I was wondering if I was missing something obvious. My class looks something like this:
public class Foo { private byte[] bar;
A table is defined in MySQL 5.5 as follows:
CREATE TABLE foo ( bar BINARY(64) NOT NULL)
And the Hibernate 3.6.2 mapping looks something like this:
<hibernate-mapping> <class name="example.Foo" table="foo"> <property name="bar" column="bar" type="binary" /> </class> </hibernate-mapping>
I use hbm2ddl only for verification, and it gives me this error when deploying the application:
Wrong column type in foo for column bar. Found: binary, expected: tinyblob
If using type = "binary" in the mapping does not cause Hibernate to expect the column type to be binary (instead of tinyblob), I don't know what it would do. I spent some time at Google, but could not find the exact error. Solutions for such errors were ...
- Specify "length" in the <property>. This changes the type of the expected Hibernate type, but it always has several varieties of blob instead of the binary type found.
- Instead of declaring a “type” in the property element, insert a column element and assign it an attribute of type sql. This work, but it will also make a MySQL-specific binding, so I would like to avoid it if possible.
Is there anything other than this setting that might cause this mismatch? If I specify type = "binary" instead of "blob", why does Hibernate expect blob instead of binary?
source share