database - Grails org.hibernate.StaleObjectStateException for simultaneous requests -
I have an app with the controller performing an update of the controller, making an update with the areas of the database. When the action is done at one time, it works fine. But when I do two actions together, I was updated by I need the controller to be able to handle the action together, for example by queuing the request and doing sequentially what is it somehow possible? Or how do I care for some of this? ( is database memory / file , As I have done a little work with it. It is not necessary to run a full scale database. Edit: Calling 'hierarchy' is as follows: This entry point is the controller. gameFlowService call:. game: and turn: I save only the game example When I add a new twist to it - I believed that being hibernate automatically logically changes any other change. Despite using the lock, I still get the same error (Stacktrace says that in the game: On the line: Edit 2: I believe that my problem is not abnormal, the controller action leads to changes in the database, and that requires serialized Is anyhow how hibernate / Grails it fixes? I think your problem is as follows: 2 simultanous threads It is possible to lock the object when it is recovered from its database. As a result, "Select to update ...", look for this link to be used: But to avoid any race conditions, you can use the lock method Your airport, such as: If you have to ask the object, then you can use the lock inside a benchmark. In an example for this criterion: org.hibernate.StaleObjectStateException error
another transaction (or unsaved value mapping or Was removed))
synchronized want to help here? Is this correct the way?)
game controller def doTurn () {stringoverflow def c = player.creterkitia () def player = c.get {eq "login", login lock true from strings login = params.login // } // Deaf Player = Player.findAllByLogin (Access) .Get (0) PlayerChoice choice = Utils.intToChoice (Integer.parseInt (params.choice) integer turnNumber = Integer.parseInt (params.turn) gameFlowService.makeTurn (Player, Option, turnNumber) DEF race = new Utils () playerStateToJSON (player) RAS RENDER AS JSON}
Game {player player 1 player player 2 int changes hteb play playlist is turned on static = [turns: turn] static insert = [tournament: tournament] public void made (turn) (turn turn = new ([play: , Turn number:), player 1: player 1, player 2: player 2, like 1: player option CHOICE_NOT_SET, choice2: PlayerChoice.CHOICE_NOT_SET, poin Ts1: 0, points2: 0]) this.addToTurns (turn) this.save (flush: true, failOnError: true)}}
this.save (flush: true, failOnError: true) )
def airport = airport.lock (10) // update lock for airport.Name = "Heathrow" airport. Save ()
def c = airport.createCriteria () .get {eq "name", name lock true}
Comments
Post a Comment