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.
StaleObjectStateException
obj.save()
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?
GameController.finish
GameService.scoreGame
I have encountered this exception many times, and usually I fix it without crossing the graph of objects.
, game.rounds :
game.rounds
def rounds = Round.findAllByGameId(game.id) rounds.each { // .... }
, , , , Grails. .
, .
, / Grails (GORM) ?
- , , . , , , @Transactional . , , , ( , ), .
@Transactional
save(), . , , - , . , , , , .
save()
( -) . "" , , .
- . Hibernate SQL , UPDATE tablename SET col1=?, col2=?, ..., colN=? where id=? and version=?. , , , , where , JDBC 0, 1, , - .
UPDATE tablename SET col1=?, col2=?, ..., colN=? where id=? and version=?
Source: https://habr.com/ru/post/1608246/More articles:Python 3.5 I can't install a pillow - pythonPython unittest Mock patch object not methods - pythonHow to force CSS auto-corrector to automatically close open content when moving from section to section - javascripthttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1608244/dynamic-number-of-nested-for-loops-to-list-unique-combinations-of-objects&usg=ALkJrhia1B4NPOivYXbg_5UM4saACXdIWwCartesian products with n number of lists - c #JavaScript sequential split () for dot notation variables - javascriptИспользование GCController с симулятором tvOS - tvosResilient Bobsleigh with Docker Deployment Failure - dockerIs it possible to change the value of the Member variable in the const function? - c ++Numpy: Как создать сетку-подобный массив? - pythonAll Articles