Grails/Groovy isn't persisting change in object's collection -


i have following problem:

my object route contains list of routepoints. when alter list, changed list saved. when next method accesses list, seems change reverted. ruled kind of transaction rollback out, b/c on end of altering method, acces list loading database , still has right (altered) size. here's code:

first altering method:

def removestationfromroute(station){     def driver = driver.get(integer.valueof(requestaccessservice.getparams().userid))     def route = driver.routes.find{         it.routedate == new date().cleartime()     }     def rp = routepoint.findbystation(station)      route.routepoints.remove(rp)      def newroute = driver.routes.find{ it.routedate == new date().cleartime()}     println 'new route size: ' + newroute.routepoints.size()      def newroute2 = route.get(route.id)     println 'new route db size: ' + newroute2.routepoints.size()  } 

both prints return size of 5, correct. right after method carried out, method executed:

def getdriverroute(){     def driver = user.get(long.valueof(params.userid))     def route = driver.routes.find{ it.routedate == new date().cleartime()}     println 'serialized route size: ' + route.routepoints.size()     def routestring = jobservice.serializeroute(route)     log.info('route ' + route.routepoints.size() + " stations serialized user " + driver.encodeashtml())     render routestring } 

which prints size of 6, if no change happened list. tried saving driver, route , routepoint after change made in "removestationfromroute"-list, checking 3 objects errors. didn't help.

thanks ideas do!

i guess have 1-n relationship between route , routepoints? like

class route {   static hasmany = [routepoints: routepoint] }  class routepoint {   static belongsto = [route: route] } 

you should not add/remove routpoints using add/remove methods of collection interface. instead should use addto*/removefrom* gorm methods, e.g.

route.addtoroutepoints(routepoint) route.removefromroutepoints(routepoint) 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -