【发布时间】:2014-11-19 11:28:05
【问题描述】:
我试图在我的 creteria 中添加一个悲观锁定,如文档中所示 http://grails.org/doc/latest/guide/GORM.html#locking 但我有一个例外:
"ERROR util.JDBCExceptionReporter - 不支持功能:"FOR UPDATE && JOIN";SQL 语句: ... org.hibernate.exception.GenericJDBCException:无法执行查询”
我尝试在两个地方加锁:
def ParentInstance = Parent.createCriteria().get {
Childs {
idEq(ChildInstance.id)
lock true
}
和
def ParentInstance = Parent.createCriteria().get {
Childs {
idEq(ChildInstance.id)
}
lock true
}
附加问题:使用悲观锁定关联是否正确?
谢谢
域
class Parent{
static hasMany = [Childs:Child]
}
class Child{
}
Datasource.groovy
dataSource {
pooled = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:h2:myApp_prodDb;MVCC=TRUE"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:myApp_testDb;MVCC=TRUE"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:myApp_prodDb;MVCC=TRUE"
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}
【问题讨论】:
-
您使用的是哪个数据库?
-
我正在使用休眠数据库
-
Hibernate 只是您的应用程序和底层数据库之间的一层。该数据库可以是 H2(Grails 提供的 in-mem 数据库)、PostgreSQL、SQL Server、Oracle、MySql ......你能列出你的
DataSource.groovy文件的内容吗(一定要删除任何私人信息,如 IP 和密码,但是)? -
我编辑了我的问题
-
谢谢您,您使用的是H2数据库,但我想我现在明白问题所在了。将发布正确的答案。
标签: hibernate grails groovy pessimistic-locking