In a grails Domain a have implemented the beforeDelete
as follow
class Shop {
def beforeDelete() {
Shop.withNewSession {
Client.findAllByShop(this)*.shop = null
}
}
}
But the client shop null value is not persisted to the DB.
If I add a manual session flush
class Shop {
def beforeDelete() {
Shop.withNewSession { s2->
Client.findAllByShop(this)*.shop = null
s2.flush()
s2.clear()
}
}
}
It works, the client shop value are nulled in the db.
Is this a Grails bug or I have misunderstand the documentation? Doesn't withNewSession
imply an automatic flush?