2011-11-06 32 views
1

剛纔我對這個問題一直耿耿於懷。 Grails不會創建必需的表,我的域中指定了 。下面是執行Grails的運行程序後所散發出來的 命令行:由於longblob,Grails不生成表格?

 [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應用程序一起工作。所以這可能是別的。

回答

0

解決:我不知道爲什麼,但我試着使用:
static mapping = { content sqlType: 'longblob' }
和它的工作.. #stupidme:d

+0

這可能不起作用,因爲grails忽略了這個定義。 – Chris

3

使用sqlType會立刻讓你依賴於數據庫。它將處理知道longblob的數據庫,但對於不知道這種類型的數據庫會失敗。相反,你可以在一個更一般的方式解釋GORM,您的數據是比平時多長:

private static final MAX_IMAGE_SIZE = 1073741824 // 4GB 

static constraints = { 
    content(maxSize:MAX_IMAGE_SIZE) 
} 

這樣做的一大優勢是,GORM將類型映射到longblob,如果數據庫認識它,否則它將映射到LOB或其他類似的:因此它是獨立於數據庫的。