Hibernate, MySQL and the 1005 ErrorCode
Today seems to be wierd error message day for me. I'm using ColdFusion ORM in my application and when adding a new persistent entity to my model which has a many-to-one association to an existing entity I was getting the error:
Exception in
Error during DDL export
(org.hibernate.JDBCException)
ErrorCode: 1005
Message: Can't create table 'mydatabase.#sql-668_e4369' (errno: 150)
SQLState: HY000
So, I tried creating the table directly in MySQL and got the same error. The error actually happens when Hibernate tries to create the Foreign Key constraint. This turns out to be due to the primary key on the table I'm linked to being an unsigned integer (BIGINT) and the foreign key column that Hibernate generated was not unsigned. Using HeidiSQL (which I prefer to MySQL workbench), I set the column to unsigned and voila - Hibernate can now create the foreign key constraint.
- Posted in:
- ColdFusion
- Hibernate


I seemed to be the only one on the internet who had this problem, well, not any more! :)
Comment by Jake "Master of the Universe" Hendy – August 31, 2011