从ER图创建grails域

时间:2015-02-01 12:27:38

标签: mysql grails gorm

我有ER图。我尝试将其描述为grails域,但在启动项目后,只存在(创建)表的一部分。我无法找到我犯错的地方。

我使用MySQL数据库,启动后只有song_tag表创建

ERD http://imagizer.imageshack.com/img661/4805/ke6jBx.png

我的grails域名

class Song {

    static hasMany = [audios: Audio, tags: Tag]

    BigInteger id

    String title
    String chorus
    Boolean chorusRepeat
    Date created
    Date updated

    static constraints = {
        tags joinTable:[name:'song_tag', key:'song_id']
    }
}


class Tag {

    static belongsTo =  Song
    static hasMany = [songs: Song]

    BigInteger id
    String name

    static constraints = {
        songs joinTable:[name: 'song_tag', key: 'tag_id']
    }
}

class Couplet {

    static belongsTo = Song

    BigInteger id
    String text
    Song song

    static constraints = {
    }
}

class Audio {

    static belongsTo = Song

    BigInteger id

    String audio
    String type
    Date created
    Date updated
    Song song

    static constraints = {
    }
}

控制台输出

  

2015-02-01 14:20:36,007 [localhost-startStop-1]错误   hbm2ddl.SchemaExport - HHH000389:不成功:创建表对联   (id decimal(19,2)not null auto_increment,version bigint not null,   song_id decimal(19,2)not null,text varchar(255)not null,primary   key(id))ENGINE = InnoDB错误| 2015-02-01 14:20:36,007   [localhost-startStop-1]错误hbm2ddl.SchemaExport - 列不正确   列'id'的说明符

谢谢

1 个答案:

答案 0 :(得分:1)

有两件事需要改变

1)

 static constraints = {
    songs joinTable:[name: 'song_tag', key: 'tag_id']
}

它应该是映射闭包而不是约束闭包

static mapping = {  songs joinTable:[name: 'song_tag', key: 'tag_id']}

2)只需从域中删除id字段,它将由Gorm自动创建。

相关问题