Grails:jodalocaldate作为MySQL数据库中的唯一键

Grails:jodalocaldate作为MySQL数据库中的唯一键,mysql,grails,jodatime,Mysql,Grails,Jodatime,我有一个具有Joda LocalDate属性的域类。此属性必须是唯一的 它使用H2工作,但使用MySQL db时,我在应用程序启动时出现以下错误: [SchemaExport.create(l.386)]Unsuccessful: create table [...] [SchemaExport.create(l.387)]BLOB/TEXT column 'mydate' used in key specification without a key length 如果删除唯一约束,它也适用

我有一个具有Joda LocalDate属性的域类。此属性必须是唯一的

它使用H2工作,但使用MySQL db时,我在应用程序启动时出现以下错误:

[SchemaExport.create(l.386)]Unsuccessful: create table [...]
[SchemaExport.create(l.387)]BLOB/TEXT column 'mydate' used in key specification without a key length
如果删除唯一约束,它也适用于MySQL

这是一个错误还是我的误解

我正在使用Grails2.2.5。 此处为域片段:

class MyClass {
    LocalDate mydate

    static constraints = {
        mydate(nullable:false, unique:true)
    }
}
dataSource {
    dbCreate = "create-drop"
    driverClassName = "com.mysql.jdbc.Driver"
    dialect = org.hibernate.dialect.MySQL5InnoDBDialect
    username = "xxx"
    password = "xxx"
    dbNamer = "myapp"
    url = "jdbc:mysql://localhost:3306/${dbNamer}?autoreconnect=true"
    logSql = true
}
数据源配置片段:

class MyClass {
    LocalDate mydate

    static constraints = {
        mydate(nullable:false, unique:true)
    }
}
dataSource {
    dbCreate = "create-drop"
    driverClassName = "com.mysql.jdbc.Driver"
    dialect = org.hibernate.dialect.MySQL5InnoDBDialect
    username = "xxx"
    password = "xxx"
    dbNamer = "myapp"
    url = "jdbc:mysql://localhost:3306/${dbNamer}?autoreconnect=true"
    logSql = true
}

胡猜,我认为
date
是mySQL中的保留字。重命名该字段,然后重试

更新:

好的,我明白了。 问题是,GORM/Hibernate不知道joda
LocalDate
class,所以它试图为它创建一个BLOB列:

[SchemaExport.create(l.387)]BLOB/TEXT列“mydate”


要修复它,您可以使用自定义hibernate类型(不知道如何),或者通过保存将属性转换为平面java的
Date
类,并在加载后返回到
LocalDate

否,抱歉:我使用的是意大利语属性名称。我将其翻译为Stackoverflow:)。为了避免误解,我编辑了我的文章。这些都是变通办法,但几个月后,我认为没有其他解决办法了。非常感谢。