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 org.hibernate.StaleObjectStateException error

  another transaction (or unsaved value mapping or Was removed))   

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?

( synchronized want to help here? Is this correct the way?)

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.

  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}   

gameFlowService call:. Flash gameflowService {def makeTurn (Player Player, PlayerChoice option, Int turnNumber) {game ... currentGame = player.currentGame Turn on PreviousTurn = CurrentGam.tagast () // I I do stuff with (if it exists) or turning it on. Gm. Activate the current () currentGame.getLastTurn (). MakeChoice (player, choice) if (currentGame! = Tap) {GameGame.save (flush: true, failOnError: true)}}

game:

  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)}}   

and turn: class turn {int parallel boolean full = wrong player player 1 player player 2 player option preference 1 player option option 2 int points 1 intensity points 2 static belongTo = [game: game] Public Zero makeChoice (Player Player, Players Choice Player charge) {// This method only changes the member variable of 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: this.save (flush: true, failOnError: true) )

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

  • one
  • A object rescues
  • An updated object
  • saves object A
  • B update object < / Li>
  • Saves the B object - & gt; StaleObjectStateException

    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: def airport = airport.lock (10) // update lock for airport.Name = "Heathrow" airport. Save ()

    If you have to ask the object, then you can use the lock inside a benchmark.

    In an example for this criterion:

      def c = airport.createCriteria () .get {eq "name", name lock true}    

  • Comments

    Popular posts from this blog

    ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

    Matlab transpose a table vector -

    c# - Textbox not clickable but editable -