由于长斑而没有生成桌子的Grails?

时间:2011-11-06 08:35:00

标签: mysql grails

我刚刚被这个问题困扰了。 Grails没有创建我所拥有的必要表 在我的域中指定。这是从中得到的 执行grails run-app后的命令行:

        [main] ERROR hbm2ddl.SchemaExport  - Unsuccessful: create table image 
(id bigint generated by default as identity (start with 1), 
version bigint not null, content longblob not null, 
content_type varchar(255), description varchar(255), 
name varchar(255), product_id bigint, size bigint not null, 
type varchar(255) not null, primary key (id))
    2011-11-06 16:25:31,142 [main] ERROR hbm2ddl.SchemaExport  - Wrong data type: 
LONGBLOB in statement [create table image (id bigint generated by default
 as identity (start with 1), version bigint not null, content longblob]

我认为这与我的域类有关。有人能指出我正确的方向吗?我使用的是grails 1.3.7,这是我的域类Image.groovy。

class Image {

    static belongsTo = Product

    Product product

    ImageType   type

    String  name
    String  description
    byte[]  content
    String  contentType
    Long    size

    static constraints = {

        product     nullable: true
        content     nullable: false
        contentType nullable: true, blank: true
        size        min: 0L
        name        nullable: true, blank: true
        description nullable: true, blank: true

    }

    static mapping = {
        content (sqlType: "longblob")
    }


}

我很惊讶,因为静态映射与我的其他grails应用程序一起工作。所以它可能是别的东西。

2 个答案:

答案 0 :(得分:3)

使用sqlType会立即使您依赖数据库。它适用于知道longblob的数据库,但对于不知道这种类型的数据库会失败。相反,你可以用更一般的方式解释GORM,你的数据比平时更长:

private static final MAX_IMAGE_SIZE = 1073741824 // 4GB 

static constraints = {
    content(maxSize:MAX_IMAGE_SIZE)
}

这样做的一大优点是,GORM会将类型映射到longblob,如果数据库知道它,否则它将映射到LOB或其他类似的:所以它与数据库无关。

答案 1 :(得分:0)

解决了:我不是为什么,但我尝试使用:
 static mapping = { content sqlType: 'longblob' }
它工作.. #stupidme:D