悲观锁定在GORM哪里查询 [英] pessimistic locking in GORM where query
问题描述
类似于
def query = Person.where {
firstName ==Bart
}
//而不是where.findAll()
列出personsLocked = where .lockAll()
我知道,我可以通过标准API实现:
列表personsLocked = Person.createCriteria()。list {
eq('firstName','Bart')
lock true
}
有没有办法通过where查询来实现这一点?
您可以使用传播点运算符并在获得结果后锁定结果。 I'd like to achieve pessimistic lock with GORM's where query. Something like I know, I can achieve that by criteria API: Is there a way to achieve this via the "where" query ? You could always use the spread dot operator and lock the results after you get them. 这篇关于悲观锁定在GORM哪里查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!的结果,其中
),并且只能从 createCriteira 提供的org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriteriaBuilder 或通过显式调用 lock()
,因此将 LockMode
更改为 LockMode.UPGRADE $ c
def query = Person.where {
firstName == "Bart"
}
//instead of where.findAll()
List personsLocked = where.lockAll()
List personsLocked = Person.createCriteria().list {
eq('firstName', 'Bart')
lock true
}
lock
is not available in the grails.gorm.DetachedCriteria (result of where
) and is only available from the org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriteriaBuilder provided by createCriteira
or by explicitly calling lock()
on the instances and thus changing the LockMode
to LockMode.UPGRADE