我刚才被这个问题难住了。 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 应用程序一起使用。所以它可能是别的东西。
最佳答案
使用sqlType
将立即使您依赖于数据库。它适用于知道 longblob 的数据库,但对于不知道这种类型的数据库会失败。相反,您可以用更一般的方式解释 GORM,即您的数据比平时更长:
private static final MAX_IMAGE_SIZE = 1073741824 // 4GB
static constraints = {
content(maxSize:MAX_IMAGE_SIZE)
}
这样做的最大好处是,如果数据库知道,GORM 会将类型映射到 longblob
,否则它将映射到 LOB 或其他类似的:所以它是独立于数据库的.
关于mysql - 由于 longblob,Grails 没有生成表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8025976/