Why is grails.gorm.autoFlush set to true not working? -


consider following code:

class user {     static constraints = {         email email: true, unique: true         token nullable: true     }      string email     string password     string token } 

@testfor(user) @testmixin(domainclassunittestmixin) class userspec extends specification {     def "email should unique"() {         when: "twice same email"         def user = new user(email: "test@test.com", password: "test")         def user2 = new user(email: "test@test.com", password: "test")          then: "saving should fail"         user.save()         !user2.save(failonerror: false)     } } 

with following configuration (part of it), application.yml:

grails:     gorm:         failonerror: true         autoflush: true 

why user2.save(failonerror: false) not returning false due not being saved database?

output of running: grails test-app *userspec:

businesssoftware.userspec > email should unique failed org.spockframework.runtime.conditionnotsatisfiederror @ userspec.groovy:40

when replace user.save() user.save(flush: true) does work.

however documentation @ https://grails.github.io/grails-doc/latest/guide/conf.html, section 4.1.3 claims that:

grails.gorm.autoflush - if set true, causes merge, save , delete methods flush session, replacing need explicitly flush using save(flush: true).

for reference output of grails --version:

| grails version: 3.0.2
| groovy version: 2.4.3
| jvm version: 1.8.0_40

and that's doing, missing here?

i think autoflush documentation misleading.

grails.gorm.autoflush - if set true, causes merge, save , delete methods flush session, replacing need explicitly flush using save(flush: true).

take @ save() methods , dosave() of gorminstanceapi. toward end of dosave() you'll see session flushed when flush parameter true:

if (params?.flush) {     session.flush() } 

there's nothing in code suggesting flush parameter can come other place what's passed save().

i not find code prove it, think autoflush comes play when hibernate session closed, such when controller or service method exists/returns.

also, gorm implementation used spock , junit not real gorm, may not use autoflush configuration.

i'm going go on limb here. haven't tried this, may able flush session manually.

@testfor(user) @testmixin(domainclassunittestmixin) class userspec extends specification {     def "email should unique"() {         when: "twice same email"         def user = new user(email: "test@test.com", password: "test")         def user2 = new user(email: "test@test.com", password: "test")         simpledatastore.currentsession.flush()          then: "saving should fail"         user.save()         !user2.save(failonerror: false)     } } 

simpledatastore comes domainclassunittestmixin.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -