我一直保存在我的數據庫實體與以下簡寫Grails的...Grails的保存方法返回null
def jim = new User(name: "Jim",
emailAddress: "[email protected]",
backOfficeUser: false,
dateCreated: Instant.now(),
lastUpdated: Instant.now(),
passwordHash: BCrypt.hashpw("secret123", BCrypt.gensalt())).save(flush: true)
這一切都似乎是工作的罰款,直到東西引起.save()和save(齊平:true)返回null。如果我改變了語句這一點,但工作罰款......然後
def jim = new User(name: "Jim",
emailAddress: "[email protected]",
backOfficeUser: false,
dateCreated: Instant.now(),
lastUpdated: Instant.now(),
passwordHash: BCrypt.hashpw("secret123", BCrypt.gensalt()))
jim.save(flush:true)
吉姆實例將立刻擁有由數據庫序列發出的ID和保存被稱爲時依然存在。
嘗試在'save'中爲第一種情況添加'failOnError:true'來查看是否有任何驗證錯誤。 – dmahapatro