0
我在Grails應用程序下面的石英工作:石英工作Grails的不能更新記錄
class DataWarehouseJob {
def execute(context) {
LeadList list = context.mergedJobDataMap.get('list')
if (list.processing) {
return
}
list.processing = true
list.save(failOnError: true)
...
}
}
list
作爲工作triggerNow
調用的參數傳遞和它填充了正確的值。該列表已經存在於數據庫中。然而,當它試圖保存列表中,會出現以下錯誤:
org.quartz.JobExecutionException: org.springframework.dao.DuplicateKeyException: A different object with the same identifier value was already associated with the session : [haystack.LeadList#169]; nested exception is org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [haystack.LeadList#169]
at grails.plugins.quartz.GrailsJobFactory$GrailsJob.execute(GrailsJobFactory.java:111)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: org.springframework.dao.DuplicateKeyException: A different object with the same identifier value was already associated with the session : [haystack.LeadList#169]; nested exception is org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [haystack.LeadList#169]
...
Caused by: org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [haystack.LeadList#169]
at org.hibernate.engine.internal.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:618)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:301)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:244)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:109)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90
...
我曾嘗試加入flush: true
作爲參數保存功能,調用列表merge
保存之前,註釋類@ExecuteInJTATransaction
,節約LeadList withNewSession
,但沒有幫助 - 相同的錯誤總是發生在同一行(list.save
)
最奇怪的是,此代碼之前工作,我不知道哪些更改可能會打破它 - 有沒有改變觸及這個類在相當一段時間。
代碼編寫Grails的3.1.5和Tomcat上8