Reputation: 6131
I am using Grails 1.3.7 and MySQL 5.1.5.5. I have a class that defines a string property like this:
class Topic {
String name;
User owner;
// other fields
static constraints = {
name(blank: false, maxSize: 1024, unique: ['owner'])
}
}
This works fine with the in-memory database, but when I deploy the WAR file, I get this error:
12/06/07 17:09:48 ERROR hbm2ddl.SchemaUpdate: Unsuccessful: create table topic (id bigint not null auto_increment, version bigint not null, date_created datetime not null, description longtext, name longtext not null, owner_id bigint not null, primary key (id), unique (owner_id, name))
12/06/07 17:09:48 ERROR hbm2ddl.SchemaUpdate: BLOB/TEXT column 'name' used in key specification without a key length
If I change the maxSize
spec to 255, everything works correctly.
My reading of the documentation was that MySQL could not figure out the key length by default to enforce the uniqueness constraint; why doesn't grails pass the maxSize value for that purpose?
UPDATE: 8 Jun 2012 Here is the hibernate specification I am using:
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider'
}
I am using com.mysql.jdbc.Driver with the mysql-connector-java-5.1.7-bin.jar
library with MySQL 5.5.
Upvotes: 1
Views: 1466
Reputation: 4096
Which version of mysql are you using, Maximum length of a varchar column could be 255 (before mysql 5.0.3) - See http://dev.mysql.com/doc/refman/5.0/en/char.html
You can try changing the column type to text
Upvotes: 1