I'm new in groovy and grails. Grails version 2.5.1 Groovy version 2.4.5 My problem is: I have an update method in customerController.
customerController:
def update(){
def map = [:]
def customerId = params.id
def newCustomer = request.JSON
def customer = customerService.updateCustomer(customerId, newCustomer)
customer.validate()
if (customer== null) {
map['success'] = false
map['message'] = "Record not found"
return map
}
if (customer.save()) {
map['success'] = true
map['data'] = customer
} else {
validateErrorService.extractErrors(customer, map)
}
return map
}
In update method I call customerService.updateCustomer
customerService:
def updateCustomer(customerId, newCustomer){
def customer = Customer.get(customerId)
if (customer == null) {
return null
}
verifyLead(newCustomer.leadId)
customer.firstName = newCustomer.firstName
customer.lastName = newCustomer.lastName
if(!customer.hasErrors())
customer.save(flush:true)
return customer
}
Then i call verifyLead method to update Lead domain
def verifyLead(jsonLead, userId){
Long leadId = jsonLead.id as Long
Lead lead = Lead.get(leadId)
lead.status = "Proceed"
lead.save(flush: true)
}
In lead domain method Lead.get(leadId) return old(cached) data So when i save: lead.save(flush: true) it error hibernate.object.staleException