Skip to content

Instantly share code, notes, and snippets.

@marcpalmer
Created November 12, 2012 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcpalmer/4058952 to your computer and use it in GitHub Desktop.
Save marcpalmer/4058952 to your computer and use it in GitHub Desktop.
Hibernate optimist locking code snippet #11
// Use any domain class
MyDomain.withTransaction { txn ->
// Load objects
def object = MyDomain.lock(params.id)
def objectList = OtherDomain.findAllBySomething('x', [lock:true])
// If you need to check versions for UX…
if (object.version != params.versionShownToUser) {
// break out of here and tell the user it changed
// good luck with that...
return
}
// Make some changes
object.property1 = 'hello'
objectList.each { o -> o.message = "testing" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment