When does grails check for object objectivity?

I am using Grails 2.5.1, and I have a controller that calls the service method, which sometimes results in StaleObjectStateException. The code in the service method has an attempt to catch around a call obj.save()that simply ignores the exception. However, when one of these conflicts occurs, an error still appears in the log and an error is returned to the client.

My GameController Code:

def finish(String gameId) {
   def model = [:]
   Game game = gameService.findById(gameId)

   // some other work

   // this line is where the exception points to - NOT a line in GameService:
   model.game = GameSummaryView.fromGame(gameService.scoreGame(game))

   withFormat {
     json {
        render(model as JSON)
     }
   }
}

My GameService Code:

Game scoreGame(Game game) {
   game.rounds.each { Round round ->
      // some other work
         try {
             scoreRound(round)
             if (round.save()) {
                 updated = true
             }
         } catch (StaleObjectStateException ignore) {
             // ignore and retry
         }
   }
}

The stack trace says that an exception is thrown from my method GameController.finish, it does not point to any code in my method GameService.scoreGame. Does this mean that Grails checks for totality at the start of a transaction, and not when trying to save / update an object?

I have encountered this exception many times, and usually I fix it without crossing the graph of objects.

, game.rounds :

def rounds = Round.findAllByGameId(game.id)
rounds.each {
   // ....
}

, , , , Grails. .

, .

, / Grails (GORM) ?

+4
1

- , , . , , , @Transactional . , , , ( , ), .

save(), . , , - , . , , , , .

( -) . "" , , .

- . Hibernate SQL , UPDATE tablename SET col1=?, col2=?, ..., colN=? where id=? and version=?. , , , , where , JDBC 0, 1, , - .

+3

Source: https://habr.com/ru/post/1608246/


All Articles