【发布时间】:2012-03-08 22:42:40
【问题描述】:
我所知道的:mongod 正在运行,数据库存在,集合存在,我可以使用 mongodb 控制台进行插入,并且通过 Grails 建立到 mongod 实例的连接(即我可以查询等等)。
其他细节:Grails 2.01、mongodb plugin 1.0.0 RC4、hibernate plugin 2.01、mongodb 2.0.3
class Node {
static mapWith = "mongo"
static constraints = {
}
ObjectId id
Integer someId //someId can be null or just non-existent
String name
}
什么不起作用:我无法通过 GORM 插入任何数据,即使我明确地将 flush 设置为 true。
def n = com.company.project.Node(name: "test")
n.save(flush:true)
我也在 Grails 控制台中尝试过,但没有错误消息。是不是我做错了什么?
【问题讨论】:
-
使用 save(failOnError:true) 查看错误信息。我的猜测是 someId 在约束中需要为空。
-
默认情况下,GORM 不允许将空值插入数据库,但您可以通过在 Config.groovy 中将其关闭全局: grails.gorm.default.constraints = { '*'(nullable: true ) }
标签: grails mongodb grails-orm grails-plugin grails-2.0