0

I have a problem about how to flush away my session after I have used it. I have called out a session and when it safe it, I want it to be flushed away.

On the save() controller it has .save flush:true but why the session had not be flushed away?

I have done some research about flushing session but unfortunately I am too noob to understand it.

Related Post :

  1. How to force flushing in Grails GORM
  2. Do I ever need to explicitly flush GORM save calls in grails?

Controller :

def create(){


   def project = session['projectName'] // call out my session
   def projectNames     = Project.findAllByProjectName(project.projectName) // find out the project name inside my session and assign it in to "projectNames"
   
   model:[projectNames:projectNames] // pass it to GSP and to let the user choose from the drop down
 
   projectNames.save flush:true // but is an error
   projectNames.currentSession.flush() //got no class currentSession

}

EDIT 1

def save() //generated by grails
{

project.save flush:true
}

Thanks in advance.

Best regards, Hee

Trainee
  • 57
  • 1
  • 7

1 Answers1

0

First thing you should look is the below line

def projectNames = Project.findAllByProjectName(project.projectName)

You are fetching the list of projects matching with the name project.projectName, so it returns an list of Project instance List<Project> projectNames.

You should call the

projectNames*.save(flush:true, failOnError: true)

I dont see any update operation in your code so just wndering why do you really need an save opration here.

Prakash Thete
  • 3,802
  • 28
  • 28
  • Thanks for replying ! "Create" controller is a form, it's generate by grails. (generate-all), so my "Safe" controller will be the button "create" that generate by grails. Since "safe" has the code "flush:true" why issit the session not flushed? * I have updated my save() controller – Trainee Sep 27 '17 at 15:08