Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails, save domain class after exception has been thrown

Using grails 3.3.8

Any domainclass.save(flush:true,failOnError:true) does not get saved if a caught exception has been thrown in the service method where the save is being issued. i.e.

try {
    //some code that throws exception
} catch (Exception exception) {
    print 'some message'
}

domainclass.save(flush:true,failOnError:true)
like image 638
TBAR Avatar asked Sep 18 '18 23:09

TBAR


1 Answers

I found a work around to the above. If you extract your try catch block and put it in a different method the domain class save does get persisted.

i.e.

callMethodThatContainsTryCatch()
domainClass.save()

instead of

try {
} catch (Exception exception) {
    println "some exception"
}

domainClass.save()

It would then appear that any exception in your method rolls back of all gorm transactions within that method.

like image 125
TBAR Avatar answered Sep 28 '22 02:09

TBAR