I have been saving entities in my database in grails with the following shorthand...
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)
It all seemed to be working fine until something caused .save() and save(flush: true) are returning null. If I change the statement to this it works fine however...
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)
The Jim instance would then immediately have an id issued by the database sequence and is persisted when save is called.
failOnError: trueinsavefor the first case to see if there is any validation error. - dmahapatro