Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails/MySQL字段长度约束_Mysql_Grails_Gorm - Fatal编程技术网

Grails/MySQL字段长度约束

Grails/MySQL字段长度约束,mysql,grails,gorm,Mysql,Grails,Gorm,我正在使用Grails1.3.7和MySQL 5.1.5.5。我有一个类,它定义了如下字符串属性: class Topic { String name; User owner; // other fields static constraints = { name(blank: false, maxSize: 1024, unique: ['owner']) } } 这在内存数据库中可以正常工作,但在部署WAR文件时,会出现以下错误:

我正在使用Grails1.3.7和MySQL 5.1.5.5。我有一个类,它定义了如下字符串属性:

class Topic {
    String name;
    User owner;
    // other fields

    static constraints = {
        name(blank: false, maxSize: 1024, unique: ['owner'])
    }
}
这在内存数据库中可以正常工作,但在部署WAR文件时,会出现以下错误:

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
如果我将
maxSize
spec更改为255,则一切正常

我对文档的理解是,MySQL无法在默认情况下计算出密钥长度以强制执行唯一性约束;为什么grails不为此传递maxSize值

更新:2012年6月8日 以下是我使用的hibernate规范:

hibernate {
    cache.use_second_level_cache=true
    cache.use_query_cache=true
    cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider'
}

我正在使用com.mysql.jdbc.Driver和mysql-connector-java-5.1.7-bin.jar库以及mysql 5.5

您使用的是哪个版本的mysql,varchar列的最大长度可能是255(mysql 5.0.3之前)-请参阅


您可以尝试将列类型更改为

您在DataSource.groovy中指定了哪个Hibernate方言?我在问题中添加了Hibernate和MySQL信息我指的是方言(应该是mysql5Innodbdial),它是在
数据源{…}中指定的
DataSource.groovy中的block。我可以确认此问题影响MySQL 5.5版。我在使用MySQL 5.5.28和Grails 2.1.1时遇到了这种情况。