从 ER 图创建 grails 域

Create grails domains from ER-diagram

我有 ER 图。我尝试将其描述为 grails 域,但在启动项目后,tables 的一部分存在(创建)。找不到哪里出错了

我使用MySQL数据库,启动后只song_tag table crated

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] ERROR hbm2ddl.SchemaExport - HHH000389: Unsuccessful: create table couplet (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 Error | 2015-02-01 14:20:36,007 [localhost-startStop-1] ERROR hbm2ddl.SchemaExport - Incorrect column specifier for column 'id'

谢谢

有两件事必须改变

1)

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

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

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

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