Skip to content

Instantly share code, notes, and snippets.

@kenota
Created December 14, 2012 01:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kenota/4281636 to your computer and use it in GitHub Desktop.
How to query FOR UPDATE NOWAIT in Grails using PostgreSQL
import org.hibernate.LockMode
// Some code skipped
Message.withTransaction {
try {
def msg = Message.withCriteria {
eq "id", Long.valueOf(messageId)
delegate.criteria.lockMode = LockMode.UPGRADE_NOWAIT
}
// Now msg is locked
} catch (Exception e) {
// If NOWAIT fails, exception will be caught here, deal with it
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment