类似于
def query = Person.where { firstName ==Bart} //而不是where.findAll()列出personsLocked = where .lockAll()我知道,我可以通过标准API实现:
列表personsLocked = Person.createCriteria()。list { eq('firstName','Bart') lock true }有没有办法通过where查询来实现这一点?
解决方案lock 在 grails.gorm.DetachedCriteria (的结果,其中),并且只能从 createCriteira 提供的org.codehaus.groovy.grails.orm.hibernate.query.AbstractHibernateCriteriaBuilder 或通过显式调用 lock(),因此将 LockMode 更改为 LockMode.UPGRADE $ c
您可以使用传播点运算符并在获得结果后锁定结果。
I'd like to achieve pessimistic lock with GORM's where query.
Something like
def query = Person.where { firstName == "Bart" } //instead of where.findAll() List personsLocked = where.lockAll()I know, I can achieve that by criteria API:
List personsLocked = Person.createCriteria().list { eq('firstName', 'Bart') lock true }Is there a way to achieve this via the "where" query ?
解决方案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
You could always use the spread dot operator and lock the results after you get them.
更多推荐
悲观锁定在GORM哪里查询
发布评论