在我的Grails項目中,我有一個石英(plugin:quartz2:2.1.6.2,但我測試過插件:quartz:1.0-RC7,但問題沒有改變)(grails 2.2.1)。Quartz作業停止在StaleObjectStateException異常處執行
我有這樣的執行方法本
class MyJob {
def concurrent = false
def execute(context){
try {
//....
// works with domains .....
myDomain.save(flush: true)
// works with domains .....
//....
sessionFactory.currentSession.flush()
} catch (org.springframework.dao.OptimisticLockingFailureException olfe) {
println "Job failed by database exception "
} catch (org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException ole){
println "Job failed by database exception "
} catch (org.hibernate.HibernateException hibe){
println "Job failed by database exception "
}
}
}
}
有時StaleObjectStateException occour工作。對於我的邏輯來說,這是可以的,我使用grails樂觀鎖,並且這種例外每週只發生一次。
問題是當這個異常發生時,Job停止再次發射。
我試着在try catch和flush hibernate session內部包裝方法代碼來捕獲異常但沒有財富。我的任何捕捉都沒有捕捉到這個例外。
在網上查找我發現這是一個old grails quartz bug但它是固定的,無論如何使用try {} catch必須繞過該錯誤。
P.S. 的作業從bootstrab通過這種類型的呼叫計劃
MyJob.schedule(10000L)
是停止調度唯一的例外是
[194949896] core.ErrorLogger Unable to notify JobListener(s) of Job that was executed: (error will be ignored). trigger= DEFAULT.MT_3tbn6lewgiqa3 job= DEFAULT.MyJob
org.quartz.SchedulerException: JobListener 'persistenceContextJobListener' threw exception: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [MyDomain#42] [See nested exception: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [MyDomain#42]]
at org.quartz.core.QuartzScheduler.notifyJobListenersWasExecuted(QuartzScheduler.java:1939)
at org.quartz.core.JobRunShell.notifyJobListenersComplete(JobRunShell.java:361)
at org.quartz.core.JobRunShell.run(JobRunShell.java:235)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [MyDomain#42]
at grails.plugin.quartz2.PersistenceContextJobListener.jobWasExecuted(PersistenceContextJobListener.groovy:46)
at org.quartz.core.QuartzScheduler.notifyJobListenersWasExecuted(QuartzScheduler.java:1937)
... 3 more
.....
events.PatchedDefaultFlushEventListener Could not synchronize database state with session
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [MyJob#42]
at MyJob.execute(MyJob.groovy:354)
at grails.plugin.quartz2.GrailsArtefactJob.execute(GrailsArtefactJob.java:57)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
在你的代碼示例你不要再追「org.hibernate.StaleObjectStateException」,所以我想這是正常的工作失敗... – moskiteau 2013-05-14 13:06:31
@moskiteau org.hibernate.StaleObjectStateException是org.hibernate.HibernateException – 2013-05-14 13:16:31