【发布时间】:2012-06-08 00:38:13
【问题描述】:
我正在使用 Grails 1.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 规格更改为 255,则一切正常。
我对文档的阅读是,默认情况下 MySQL 无法计算密钥长度以强制执行唯一性约束;为什么 grails 不为此目的传递 maxSize 值?
更新:2012 年 6 月 8 日 这是我正在使用的休眠规范:
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider'
}
我正在使用带有mysql-connector-java-5.1.7-bin.jar 库的 com.mysql.jdbc.Driver 和 MySQL 5.5。
【问题讨论】:
-
您在 DataSource.groovy 中指定了哪种 Hibernate 方言?
-
我在问题中添加了休眠和 MySQL 信息
-
我的意思是方言(应该是 MySQL5InnoDBDialect),它在 DataSource.groovy 的
dataSource { ... }块中指定。
标签: mysql grails grails-orm