0

我已经为这个错误苦苦挣扎了一个星期,我为此严重失去了理智!我已经尝试过多种实现、变通方法和黑客攻击等等,但我只是不断陷入另一个例外。

我正在使用 Executor 插件异步运行方法:

runAsync{
   run(...)
}

该方法最初会删除一些对象:

page.delete(flush:true)

然后可能会重新创建这些对象:

def page = new Page(type : Page.TYPE_TABLE, domain : domainVersion.domain, identifier : tableName)
page.save(flush: true, failOnError: true)

但这失败了,但有以下例外:

Caused by: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.ramboll.egs.ohs.domain.Domain#1]

Page和之间的关系Domain只是通过Page拥有一个Domain属性来实现。没有hasManyog belongsTo- 由于性能问题,我在之前的帖子中对此感到气馁。

我想我已经尝试了所有可以想到的组合save,mergewithTransachtion...PersistenceContextInterceptor

这应该如何工作?请举例。

提前致谢!

4

1 回答 1

0

在新线程中工作似乎不是问题,它看起来像是一个标准的验证问题。这表示Page为空,表示验证错误,因为如果成功,或者null如果存在一个或多个验证错误,save() 将返回实例。有几个选项:

def page = new Page(type : Page.TYPE_TABLE,
     domain: dbUpdate.domainVersion.domain, identifier: tableName)
page.save(flush:true)
if (page.hasErrors()) {
   // handle errors
}
else {
   def pageVersion = createPageVersion(page, dbUpdate.domainVersion,
       con, tableName, dbUpdate.author).save(flush:true)
}

或用于failOnError抛出异常:

def page = new Page(type : Page.TYPE_TABLE, identifier: tableName,
     domain: dbUpdate.domainVersion.domain).save(flush:true, failOnError: true)
def pageVersion = createPageVersion(page, dbUpdate.domainVersion,
    con, tableName, dbUpdate.author).save(flush:true)
于 2011-08-12T17:12:56.517 回答