Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7979073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:40:21+00:00 2026-06-04T09:40:21+00:00

The update action in Grails first checks for the version of the object to

  • 0

The update action in Grails first checks for the version of the object to be updated and then updates it.
What part of Grails ensures that the object isn’t updated by another request during checking the version and updating the object?

Update:

Yes, hibernate will check for the version when savin the object and will throw an exception is optimistic locking fails. And I guess hibernate will make sure that the check+update is atomic, but…

if you take a look at the grails generated update method, you’ll find that grails first double-checks and then (from my point of view) isn’t prepared to handle the exception. The chances that hibernate will throw an exception after the update method has already checked for the right version are small, but it seems possible to me.

So wouldn’t it be enough to try a save and catch the exception (if there is one)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:40:23+00:00Added an answer on June 4, 2026 at 9:40 am

    It’s managed by Hibernate layer. It’s called ‘optimistic locking’, and basically it updates only a object with a known version. Like:

    UPDATE SET
      %... fields ...%, 
      version = version + 1                      --update version to a new value
    WHERE 
      id = %obj id%                              --current object
      AND version = %previous obj version%`      --last known version 
    

    And throw exception when it fails to update (btw, at this moment it’s hard to recover from this error, at most cases you just losing your update).

    If you want to be sure that data is saved, try to force data saving (and check for saving/validtion error):

    try {
        if (!obj.save(flush: true)) {
            // validation error
        }
    } catch (OptimisticLockingFailureException e) {
        // not saved
    }
    

    or even lock data before update. It’s useful only when you have a lot of concurrent updates.

    MyDomain obj = MyDomain.lock(params.id) //now it's locked for update
    // update fields
    obj.save()
    

    See more details about GORM locking at http://grails.org/doc/latest/guide/GORM.html#locking

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an update action in a controller that performs an UpdateModel. Before I
I have controller action in which I update a simple value in domain object:
I have an update action that I post to using jquery serialize() public ActionResult
About every 3rd time my app serves a particular update action (two that I've
Can this <%= link_to 'Item', {:controller => items, :action => update, :id => @item,
I want to implement a Facebook updates(user action and notifications) on my web application
def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
[Update]: my initial example doesn't reflect my problem. Updated the sample, hopfully it is
The Grails documentation for the remoteFunction update attribute states: update (optional) - Either a
Assume the following code in a Grails controller: def action = { ClassName o

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.