gpt4 book ai didi

hibernate - grails/hibernate:在作业中获取org.hibernate.StaleStateException

转载 作者:行者123 更新时间:2023-12-02 14:49:39 26 4
gpt4 key购买 nike

我有一个不系统地发生的异常(exception)。
我试图通过在每次迭代中刷新和清理 session 来解决此问题,但没有成功。

[quartzScheduler_Worker-7] ERROR jdbc.AbstractBatcher  - Exception executing batch: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at bosmonitor.MyJob$_execute_closure1.doCall(MyJob.groovy:27)
at bosmonitor.MyJob.execute(MyJob.groovy:25)
at grails.plugins.quartz.GrailsJobFactory$GrailsJob.execute(GrailsJobFactory.java:102)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)


class Product {
int duration = 0
int timer = 0
// ...

static mapping = {
version false
}
}

通过添加调用该作业的服务来发布更新。

我的服务
def ProductInstance = Product.get(1)

MyJob.schedule(1000L,0)
MyJob.triggerNow([ProductInstance:ProductInstance])

工作
class MyJob {
def sessionFactory

static triggers = {}

def execute(context) {
def ProductInstance = context.mergedJobDataMap.get('ProductInstance')

if (ProductInstance) {
// loop every second
while (ProductInstance.timer < ProductInstance.duration) {
def millis = System.currentTimeMillis()

Product.withTransaction {
ProductInstance.timer = ++ProductInstance.timer
ProductInstance.merge(flush: true)
def hibSession = sessionFactory.getCurrentSession()
hibSession.flush()
hibSession.clear()
}
Thread.sleep(1000 - millis % 1000)
}
}
}
}

最佳答案

省略withSession的内容,然后将事务代码放入服务中?

同样,在保存时启用failOnError有时有助于获取根本错误...

关于hibernate - grails/hibernate:在作业中获取org.hibernate.StaleStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39222758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com